< Go Back Home

First Game in Javascript

? GAME TIME ?

Today is Day 8 of #100DaysofCode, and I’ve just finished building a little game in JavaScript! You can guess how many fingers Homer is holding up. If you’re right, your browser will let you know you’ve won; if you’ve lost, your browser will alert you and also let you know what the random number was. You can check it out (and all of the corresponding code!) on my codepen. ?


So what’s going on here under the hood? JavaScript is selecting a number between 0 and 5, and calls that a variable. It also turns your guess into a variable. Then, when you click “guess,” it attempts to reconcile the two:

? If you’ve won, your browser will let you know. Good job!

? If you’ve lost, your browser will also alert you. (Better luck next time!) .

Check it out and play here!

Coded by Chloe on May 1st, 2024