ES6 Day 2: Homework and correction

Hi Abiola, that is quite a bit to go through.

First of all may I point you to the option to make proper screenshots in future? Windows has a nifty tool built in called the ‘snipping tool’ https://www.youtube.com/watch?v=2O932t8-k2A or its alternative the ‘snip and sketch’ tool https://www.youtube.com/watch?v=FPXTvrY7yc4 which allows you to make each screenshots that are much better readable for us that want to try and help.

Then let’s go through your code bit by bit.
‘Selecting from many Options with Switch Statements’ (your picture IMG_20220916_163115_726.jpg and IMG_20220916_163041_019.jpg)

This problem is being discussed here:

Take a look and see if that helps you.

The second problem, is kind of the same, but it does require you to understand how a switch works. I have a post here that tries to explain the switch with examples:

See if that gives you some understanding, with this clue and the previous assignment I think you may be able to solve it.
A few tips here:

  1. Do not try to just ‘copy’ what you see in the example on the page but look at the construction of the function to start with. See how it gets a parameter val in the function call function switchOfStuff(val) { ...} ? That means we do not know about a ‘num’ but only about a ‘val’, and that is what we should test.
  2. There is a default call to the function at the end switchOfStuff(1); where you can see that the value that is passed into the function is a number. But then you call it with console.log(switchOfStuff(a)); how is it to know what a is? You did not put it in as the letter a, because that would have been “a”, but like a variable a without assigning it.

Your switch statement here in itself is very close to correct though, just have another try after you read the linked posts. I am sure you will get it - if you need more help - just shout out!

Then the Card Counting problem. That is a really tough one, but we also discussed that a few times. See if the above posts in combination with this one help:

You may want to browse up a bit in that thread to see Lina’s question too. She was also very close in solving it. Let us know if you need further help with any of these after reading through the posts and trying the exercises again! You got this!

3 Likes