Lab 17 Reflection
Now it was time to make the JS functions that would make the game work. I created one large function, play(move), which took in a parameter describing what move the player made. Within this function, the computer would randomly make a move via RNG, assigning a particular move to a particular number from 1 - 3. The move the computer made was stored in a variable, var cpuMov, and was compared to the user's move through a series of if statements, with 3 statements in total checking for 9 total conditions. The results of the match, including the move the player made, the computer's move, and who won were displayed using DOM to change the contents of an <h2> tag placed in the instructions and results div earlier.
These skills are useful for a web designer that is going into game-making. Knowing how to create a layout that displays the player's actions and abilities make the experience intuitive and using elements such as color to create contrast help convey what the user should be doing, in this case playing against the computer. Knowing how to use functions within the JS library, such as Math.random(), to create game logic is also vital in making the game work.
Comments
Post a Comment