Declaring variables in JS is done using keywords such as let, const or var. That's why you see the let keyword in this example. As for why it outputs Friday (I think this is an error on the teacher side), because the Date object in JS has a method getDay which takes his Local Time and on the day of him writting this code it was Friday so it outputs it.
@@ABunchaHerbs take the animal example, let's say using "Spoon". The switch evaluates "Spoon" against Cow, Giraffe, Dog, Pig. Because None of those are true, the code within the switch doesn't execute (so no break or no console log). So, it continues to the next switch statement. This time, it compares "Spoon" to Spoon, which fires back True to the switch. As a result, the code executes, and the console log and break goes through (the break exits the entire switch statement). Let's say he didn't have break there, just console log. Console log would execute, and then it would proceed to the next switch (dinosaur and default). since default will always execute to true, it's basically saying if animal === dinosaur || animal. (that is, animal has ANY value). so the last switch would execute too. As a result, you breaks are used to avoid that happening.
@Charlie Ennis they're not bad in languages where you don't have to type break everytime. and yes they are faster. really weird he doesn't mention that here, since that's the only reason to use a switch
how come when it says Case followed by a number the number is not in parentheses but when it is Case followed by a word or letter they are in parentheses? case 1 case "a"
you mean quotation marks? That is because the value can be number (Ex. 1,) or it could be string (Ex. "a"). Quotation marks indicate that that is string.
//By their present number on earth var dinosaur = 0; //? var chicken = 300000; //even more if(dinosaur>=chicken){ alert("we have lived way before you")} else { alert("You're a joke, no one knows when you existed")} ;
That example actually came from the Mozilla Developer Network article on Switch statements. But I think the idea is that dinosaurs were extinct before the arc. 😃
Declaring variables in JS is done using keywords such as let, const or var. That's why you see the let keyword in this example. As for why it outputs Friday (I think this is an error on the teacher side), because the Date object in JS has a method getDay which takes his Local Time and on the day of him writting this code it was Friday so it outputs it.
thank you so much Beau! love your ending tag! "use your code for good" :)
Love that too
i am very impressed the videos about js and especially buea teacher😍
Got a little lost on how you got Friday for the first example.. If someone can explain that would be great
Program got data from his local PC :)
@@ukaszkiepas57 I am guessing that's what the command getDay has accomplished right?
@@HarryInShape correct
i don't think i've ever used a switch. they're bad because you have to remember to break; just use else if
yeh im just stating out js but I don't rlly understand what break does in this loop
@@ABunchaHerbs take the animal example, let's say using "Spoon". The switch evaluates "Spoon" against Cow, Giraffe, Dog, Pig. Because None of those are true, the code within the switch doesn't execute (so no break or no console log). So, it continues to the next switch statement. This time, it compares "Spoon" to Spoon, which fires back True to the switch. As a result, the code executes, and the console log and break goes through (the break exits the entire switch statement). Let's say he didn't have break there, just console log. Console log would execute, and then it would proceed to the next switch (dinosaur and default). since default will always execute to true, it's basically saying if animal === dinosaur || animal. (that is, animal has ANY value). so the last switch would execute too. As a result, you breaks are used to avoid that happening.
@@endyy6671 thanks!
@@endyy6671 awesome explanation!
@Charlie Ennis they're not bad in languages where you don't have to type break everytime. and yes they are faster. really weird he doesn't mention that here, since that's the only reason to use a switch
Fantastic explanation
Free and concise, nice!
Thank you Beau!
How does the first switch case know that it's Friday though? Does it reference some kind of global property?
Thanks for this.much appreciation
Got it now, thank you!
how come when it says Case followed by a number the number is not in parentheses but when it is Case followed by a word or letter they are in parentheses?
case 1
case "a"
you mean quotation marks? That is because the value can be number (Ex. 1,) or it could be string (Ex. "a"). Quotation marks indicate that that is string.
what does let day; mean?
let day what? we did not assign any value to this variable here ... Why?
its creating a variable but instead of var its let.
Can this be done with changing background colors on a webpage? If so how exactly
Ok dinosaurs are extinct... but poor chickens :(
Chickens are the direct descendent of dinosaurs tho lol
dinosaurs >= chickens
@@philipdufour7233 if(dinosaurs >= chickens) {
alert("dinosaurs are bigger then chickens.");
}
//By their present number on earth
var dinosaur = 0; //?
var chicken = 300000; //even more
if(dinosaur>=chicken){
alert("we have lived way before you")}
else {
alert("You're a joke, no one knows when you existed")} ;
Much love Beau! Thanks for your videos
Thanks👍
what is the function of case? why is it there.
can i ask which editor u r using?
kyle Yeung CodePen, I guess
Yeah, it is codepen.
@@BeauCarnes Sir, are you Jewish?
@@fahimemroz9141 why do you ask?
@@Mogwai88 Just curious
day in switch is variable?
thanks, I'm sick of using if statement over and over
break; not Break;
pas mal
thank you!!!!! I love freecodecamp.org
Love youuuu
So you think that all dinosaurs were able to swim?
That example actually came from the Mozilla Developer Network article on Switch statements. But I think the idea is that dinosaurs were extinct before the arc. 😃
It's almost 2019 and this still don't make sense
Always the same example given on every videos.....................................................
wat
please avoid this channel they're terrible at explaining code with the worst examples lmao.
😂
That was a terrible discussion of switch statements;. totally confusing.
Not described well enough here
ua-cam.com/video/UeXDAu7SdmY/v-deo.html
check this for a more noob friendly video to get what happens here. cheers.