Skip to content

Instantly share code, notes, and snippets.

@courtney-scripted
Created March 10, 2017 16:35
Show Gist options
  • Save courtney-scripted/012cde3c66884311775448d91cff44d0 to your computer and use it in GitHub Desktop.
Save courtney-scripted/012cde3c66884311775448d91cff44d0 to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=012cde3c66884311775448d91cff44d0
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
</body>
</html>
//Task 1. On line 2, create an array named RPS that contains the items "rock", "paper", and "scissors".
var RPS= ["rock", "paper", "scissors"];
//Task 2. On line 9, write a line of code that prints "paper" from the array to the console.
console.log(RPS [1]);
//Task 3. On line 11, declare a variable named random which should be equal to the product of a random number between 0-1 and the length of the array.
var random = Math.random() * RPS.length;
//Task 4. On line 13, define a new variable called index. This variable should be equal to the floored value of the random number. (Hint: Use Math.floor())
var index = Math.floor(random);
console.log(index);
//Task 5. Write a line of code that will print a random item in the array by using the index variable generated above.
console.log(RPS[index]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment