Switch Statements - Beau teaches JavaScript

Поділитися
Вставка
  • Опубліковано 22 жов 2024

КОМЕНТАРІ • 58

  • @MarkoMajstorovic-s6e
    @MarkoMajstorovic-s6e Рік тому +1

    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.

  • @bridget7223
    @bridget7223 3 роки тому +12

    thank you so much Beau! love your ending tag! "use your code for good" :)

  • @NidaAslam-l2x
    @NidaAslam-l2x 11 місяців тому

    i am very impressed the videos about js and especially buea teacher😍

  • @MiguelVargas-pz5zv
    @MiguelVargas-pz5zv 5 років тому +23

    Got a little lost on how you got Friday for the first example.. If someone can explain that would be great

    • @ukaszkiepas57
      @ukaszkiepas57 5 років тому +22

      Program got data from his local PC :)

    • @HarryInShape
      @HarryInShape 2 роки тому

      @@ukaszkiepas57 I am guessing that's what the command getDay has accomplished right?

    • @postingbmwm3
      @postingbmwm3 2 роки тому +1

      @@HarryInShape correct

  • @stephenkamenar
    @stephenkamenar 4 роки тому +8

    i don't think i've ever used a switch. they're bad because you have to remember to break; just use else if

    • @ABunchaHerbs
      @ABunchaHerbs 4 роки тому +1

      yeh im just stating out js but I don't rlly understand what break does in this loop

    • @endyy6671
      @endyy6671 4 роки тому +10

      @@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.

    • @c0zy23
      @c0zy23 4 роки тому

      @@endyy6671 thanks!

    • @chascript
      @chascript 3 роки тому

      @@endyy6671 awesome explanation!

    • @stephenkamenar
      @stephenkamenar 3 роки тому

      @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

  • @SF-ve3rc
    @SF-ve3rc 4 роки тому +2

    Fantastic explanation

  • @jaylavan7392
    @jaylavan7392 4 роки тому +5

    Free and concise, nice!

  • @vasilemidrigan50
    @vasilemidrigan50 3 роки тому +1

    Thank you Beau!

  • @CiscoZero
    @CiscoZero 2 роки тому

    How does the first switch case know that it's Friday though? Does it reference some kind of global property?

  • @BuzzMarketingKe
    @BuzzMarketingKe 2 роки тому

    Thanks for this.much appreciation

  • @luiscamacho1996
    @luiscamacho1996 3 роки тому +1

    Got it now, thank you!

  • @simplefit93
    @simplefit93 Рік тому +1

    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"

    • @islombekmirsalimov3185
      @islombekmirsalimov3185 Рік тому +1

      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.

  • @syedarmaghanhassan4652
    @syedarmaghanhassan4652 3 роки тому +2

    what does let day; mean?
    let day what? we did not assign any value to this variable here ... Why?

    • @erichernandez38
      @erichernandez38 3 роки тому

      its creating a variable but instead of var its let.

  • @MilesLogan91
    @MilesLogan91 2 роки тому

    Can this be done with changing background colors on a webpage? If so how exactly

  • @Gentarozzo
    @Gentarozzo 7 років тому +12

    Ok dinosaurs are extinct... but poor chickens :(

    • @fionashaw6935
      @fionashaw6935 3 роки тому +2

      Chickens are the direct descendent of dinosaurs tho lol

    • @philipdufour7233
      @philipdufour7233 3 роки тому +2

      dinosaurs >= chickens

    • @abdullahmazhar9932
      @abdullahmazhar9932 3 роки тому +1

      @@philipdufour7233 if(dinosaurs >= chickens) {
      alert("dinosaurs are bigger then chickens.");
      }

    • @chinweikes.okenyi6163
      @chinweikes.okenyi6163 2 роки тому

      //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")} ;

  • @reidwilliamson6477
    @reidwilliamson6477 3 роки тому +1

    Much love Beau! Thanks for your videos

  • @gilbertquaye1571
    @gilbertquaye1571 2 роки тому

    Thanks👍

  • @orion.5611
    @orion.5611 3 роки тому

    what is the function of case? why is it there.

  • @kyleyeung1075
    @kyleyeung1075 7 років тому +1

    can i ask which editor u r using?

    • @wattabak9890
      @wattabak9890 7 років тому

      kyle Yeung CodePen, I guess

    • @BeauCarnes
      @BeauCarnes 7 років тому +2

      Yeah, it is codepen.

    • @fahimemroz9141
      @fahimemroz9141 5 років тому +2

      @@BeauCarnes Sir, are you Jewish?

    • @Mogwai88
      @Mogwai88 3 роки тому

      @@fahimemroz9141 why do you ask?

    • @fahimemroz9141
      @fahimemroz9141 3 роки тому

      @@Mogwai88 Just curious

  • @nguyenthanh5719
    @nguyenthanh5719 6 років тому

    day in switch is variable?

  • @DIZZYplys
    @DIZZYplys Рік тому

    thanks, I'm sick of using if statement over and over

  • @Gummylongtail
    @Gummylongtail 4 роки тому

    break; not Break;

  • @adil88201
    @adil88201 2 роки тому

    pas mal

  • @climbers1376
    @climbers1376 6 років тому +5

    thank you!!!!! I love freecodecamp.org

  • @ukaszkiepas57
    @ukaszkiepas57 5 років тому +1

    Love youuuu

  • @PhilippeRigovanov
    @PhilippeRigovanov 7 років тому

    So you think that all dinosaurs were able to swim?

    • @BeauCarnes
      @BeauCarnes 7 років тому +1

      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. 😃

    • @marciopires4969
      @marciopires4969 5 років тому +1

      It's almost 2019 and this still don't make sense

  • @nielsnet4169
    @nielsnet4169 4 роки тому +1

    Always the same example given on every videos.....................................................

  • @faithpublico9484
    @faithpublico9484 3 роки тому

    wat

  • @kmachappy5176
    @kmachappy5176 2 роки тому +1

    please avoid this channel they're terrible at explaining code with the worst examples lmao.

  • @peterwoods35
    @peterwoods35 5 років тому +7

    That was a terrible discussion of switch statements;. totally confusing.

  • @typingmasterpro6762
    @typingmasterpro6762 3 роки тому

    Not described well enough here

  • @yohanjayawardena4457
    @yohanjayawardena4457 2 роки тому

    ua-cam.com/video/UeXDAu7SdmY/v-deo.html
    check this for a more noob friendly video to get what happens here. cheers.