Week 5: Vincent’s (if/else) Javascript exercise – Moon

For this javascript exercise, in order to finish it, you had to understand the logic of the if/else statement.

The first step I took was to create the actual HTML file, which is just standard “head” “body” stuff.

I gave each of the images their own ID, which would be useful later in the javascript and CSS.

The second step I took was to do some CSS, specifically giving the images a opacity and also the images a flex box.

The last step is the javascript, which I was stuck on a simple mistake. I understood the logic of the function, and felt like there shouldn’t have been any problem with the coding.

Problem coding:

This coding didn’t work and I was utterly confused by it, until the next day when I was playing around and saw the red squiggly under the last “else if” statement. I removed the if, and then it instantly worked.

Overall, the exercise wasn’t very hard because all it took was just to understand the logic of the “if/else” statement. I had made it hard by not seeing one of the easy mistakes.

Link to exercise

Leave a Reply