Due: Friday, Oct. 9th by 8:00pm
So far the two players in the Game are rather predictable. We will now create a player who is more... random. We'll call this new player Random Riko.
randomRiko.js
.
"Random Riko"
.
To code Random Riko, we will use the JavaScript function Math.random()
.
Math.random()
returns a randomly generated number in the range [0, 1).
This means one time it might be 0.39894, another time 0.98532, and another time 0.10934.
The following code is the start of Random Riko's makeDecision
function:
// Program the makeDecision function to play in the contest! makeDecision: function(me, partner, capital) { var randomNumber = Math.random(); }
To finish this function:
randomNumber
is less than 0.5.
If so, return "h"
. Otheriwse, return "s"
.
players/randomRiko.js
.
If you completed everything correctly so far, you can run your second CS 105 Hunger Games!
cs105HungerGames.html
in a web browser.
If everything works, you should be able to watch CS 105's Hunger Games unfold before your very eyes! Specifically, you should see Hue the Hunter, Sam the Slacker, and Random Riko: