Last active
February 15, 2017 23:32
-
-
Save RCTumolac/9006b78ab0c104a714091f1401ce7657 to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=9006b78ab0c104a714091f1401ce7657
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Dice Simulator</title> | |
</head> | |
<body> | |
<!-- Put your page markup here --> | |
<button id = "1"> Click for a dice roll</button> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"enabledLibraries":["jquery"]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Dice Game | |
Directions: Make a program that randomly displays a number 1 through 6 | |
Instructions: | |
1. On line 19, Use Math.random() to display a random number between 0 and 1 | |
What do you see printing to the console? | |
2. Multiply your Math.random() function by 6 | |
What do you see printing to the console? | |
3. Place your code in a function called Math.floor() to only display whole numbers between 0 and 5 | |
What do you see printing to the console? | |
4. Add the number 1 to your function call to display a random number between 1 and 6 | |
Is this simulating a 6 sided die properly? | |
*/ | |
$("button").click(function(){ | |
var dice = | |
//To do: Insert your code here | |
Math.floor(Math.random()*(6)+1); | |
var dice2 = | |
//To do: Insert your code here | |
Math.floor(Math.random()*(6)+1); | |
$("body").append("<p>" + dice + " " + dice2 + "</p>"); | |
console.log(dice); | |
}); | |
//Bonus steps | |
// added a second die so that it simulates a user rolling 2 dice at once |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment