You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
console.log("It costs $"+(adult ? "40.00" : "20.00")+" to attend the concert. Pick up your tickets at the "+(preorder ? "will call" : "the gate")+".");
172
+
// prints: It costs $40.00 to attend the concert. Pick up your tickets at the will call.
173
+
174
+
/*
175
+
* Programming Quiz - Navigating the Food Chain (3-8)
176
+
*
177
+
* Use a series of ternary operator to set the category to one of the following:
178
+
* - "herbivore" if an animal eats plants
179
+
* - "carnivore" if an animal eats animals
180
+
* - "omnivore" if an animal eats plants and animals
181
+
* - undefined if an animal doesn't eat plants or animals
182
+
*
183
+
* Notes
184
+
* - use the variables `eatsPlants` and `eatsAnimals` in your ternary expressions
185
+
* - `if` statements aren't allowed ;-)
186
+
*/
187
+
188
+
// change the values of `eatsPlants` and `eatsAnimals` to test your code
189
+
//currently not finished yet!
190
+
vareatsPlants=false;
191
+
vareatsAnimals=false;
192
+
193
+
varcategory=(eatsPlants? "herbivore" : "carnivore")&&(eatsAnimals? "canivore": "herbivore")&&(eatsAnimals&&eatsPlants? "omnivore":"undefined");/* your code goes here */
194
+
195
+
console.log(category);
196
+
197
+
/*A switch statement is an another way to chain multiple else if statements,
198
+
that are based on the same value without using conditional statements.
199
+
Instead, you just switch which piece of code is executed based on a value.*/
200
+
201
+
//example 1 as an else if
202
+
varoption=3;
203
+
if(option===1){
204
+
console.log("You selected option 1.");
205
+
}elseif(option===2){
206
+
console.log("You selected option 2.");
207
+
}elseif(option===3){
208
+
console.log("You selected option 3.");
209
+
}elseif(option===4){
210
+
console.log("You selected option 4.");
211
+
}elseif(option===5){
212
+
console.log("You selected option 5.");
213
+
}elseif(option===6){
214
+
console.log("You selected option 6.");
215
+
}
216
+
217
+
//example 1 as a switch statement
218
+
varoption=3;
219
+
switch(option){
220
+
case1:
221
+
console.log("You selected option 1.");
222
+
case2:
223
+
console.log("You selected option 2.");
224
+
case3:
225
+
console.log("You selected option 3.");
226
+
case4:
227
+
console.log("You selected option 4.");
228
+
case5:
229
+
console.log("You selected option 5.");
230
+
case6:
231
+
console.log("You selected option 6.");
232
+
}
233
+
234
+
/*Prints:
235
+
You selected option 3.
236
+
You selected option 4.
237
+
You selected option 5.
238
+
You selected option 6.*/
239
+
240
+
//example 1 as a break statement
241
+
varoption=3;
242
+
switch(option){
243
+
case1:
244
+
console.log("You selected option 1.");
245
+
break;
246
+
case2:
247
+
console.log("You selected option 2.");
248
+
break;
249
+
case3:
250
+
console.log("You selected option 3.");
251
+
break;
252
+
case4:
253
+
console.log("You selected option 4.");
254
+
break;
255
+
case5:
256
+
console.log("You selected option 5.");
257
+
break;
258
+
case6:
259
+
console.log("You selected option 6.");
260
+
break;// technically, not needed
261
+
}
262
+
//Prints: You selected option 3.
263
+
264
+
//Falling-through
265
+
266
+
vartier="nsfw deck";
267
+
varoutput="You’ll receive "
268
+
269
+
switch(tier){
270
+
case"deck of legends":
271
+
output+="a custom card, ";
272
+
case"collector's deck":
273
+
output+="a signed version of the Exploding Kittens deck, ";
274
+
case"nsfw deck":
275
+
output+="one copy of the NSFW (Not Safe for Work) Exploding Kittens card game and ";
276
+
default:
277
+
output+="one copy of the Exploding Kittens card game.";
278
+
}
279
+
280
+
console.log(output);
281
+
//Prints: You’ll receive one copy of the NSFW (Not Safe for Work) Exploding Kittens card game and
282
+
//one copy of the Exploding Kittens card game.
283
+
284
+
/*
285
+
* Programming Quiz: Back to School (3-9)
286
+
*/
287
+
288
+
// change the value of `education` to test your code
289
+
vareducation="no high school diploma";
290
+
291
+
// set the value of this based on a person's education
292
+
varsalary;
293
+
294
+
// your code goes here
295
+
switch(education){
296
+
case"no high school diploma":
297
+
salary=("earned an average of $25,636/year");
298
+
break;
299
+
case"a high school diploma":
300
+
salary=("earned an average of $35,256/year");
301
+
break;
302
+
case"an Associate's degree":
303
+
salary=("earned an average of $41,496/year");
304
+
break;
305
+
case"a Bachelor's degree":
306
+
salary=("earned an average of $59,124/year");
307
+
break;
308
+
case"a Master's degree":
309
+
salary=("earned an average of $69,732/year");
310
+
break;
311
+
case"a Professional degree":
312
+
salary=("earned an average of $89,960/year");
313
+
break;
314
+
case"a Doctoral degree":
315
+
salary=("earned an average of $84,396/year");
316
+
break;// technically, not needed
317
+
318
+
}
319
+
console.log("In 2015, a person with "+education+" earned an average of "+salary+".");
320
+
321
+
//Example of an else if statement
322
+
// change the value of `weather` to test your conditional statements
323
+
varweather="snow";
324
+
if(weather==="snow"){
325
+
console.log("Bring a coat.");
326
+
}elseif(weather==="rain"){
327
+
console.log("Bring a rain jacket.");
328
+
}else{
329
+
console.log("Wear what you have on.");
330
+
}
331
+
332
+
//Example of an if else statement
333
+
vara=1;
334
+
varb=2;
335
+
336
+
if(a>b){
337
+
console.log("a is greater than b");
338
+
}else{
339
+
console.log("a is less than or equal to b");
340
+
}
341
+
342
+
//Example of an else if statement
343
+
// change the value of `musicians` to test your conditional statements
344
+
varmusicians=1;
345
+
346
+
if(musicians<=0){
347
+
console.log("not a group");
348
+
}elseif(musicians==-1){
349
+
console.log("not a group");
350
+
}elseif(musicians==1){
351
+
console.log("solo");
352
+
}elseif(musicians==2){
353
+
console.log("duet");
354
+
}elseif(musicians==3){
355
+
console.log("trio");
356
+
}elseif(musicians==4){
357
+
console.log("quartet");
358
+
}else{
359
+
console.log("this is a large group");
360
+
}
361
+
362
+
363
+
//Javascipt for making the topbanner of your page the same height of the device
364
+
//just change the '.topbanner' to the name of the class for your top banner or jumbotron.
0 commit comments