I'd like to run this program ouside of Codeacademy

javascript

#1

I've created this code in JS (it is a version of Rock, Paper, Scissors from 9/9 except I added lizard and Spock and I've had no problem with it, but I would like to run it outside of Codeacademy (in my browser, for example). I've tried using html but I don't really know anything about it and it doesn't work.

Here's the code:

console.log("Welcome to rock, paper, scissors, lizard, Spock!")
var userChoice = prompt("Do you choose rock, paper, scissors, lizard or Spock?");
var computerChoice = Math.random();
if (computerChoice <= 0.20) {
computerChoice = "rock";
} else if(computerChoice <= 0.40) {
computerChoice = "paper";
} else if(computerChoice <=0.60) {
computerChoice = "scissors";
} else if(computerChoice <=0.80) {
computerChoice = "lizard"
} else {
computerChoice = "Spock"
}

console.log("Computer: " + computerChoice);

var compare = function(choice1, choice2) {
if(choice1 === choice2) {

"The result is a tie!"

}

else if(choice1 === "rock") {

if(choice2 === "scissors") {
    return "Rock crushes scissors"
}
else if(choice2 === "spock") {
   return "Spock vaporizes rock";
    
}
else if(choice2 === "lizard") {
    return "Rock crushes lizard"
}
else {
    return "Paper covers rock"
}

}

else if(choice1==="dog") {
return "...what?.";

}

else if(choice1 === "paper") {
if(choice2==="rock") {
return "Paper covers rock";
}
else if(choice2==="scissors") {
return "Scissors cuts paper";
}
else if(choice2==="lizard") {
return "Lizard eats paper";
}
else {
return "Paper disproves spock";
}
}

else if(choice1==="scissors") {
if(choice2==="rock") {
return "Rock crushes scissors"
}
else if(choice2==="paper") {
return "Scissors cuts paper";
}
else if(choice2==="lizard") {
return "Scissors decapitates lizard"
}
else {
return "Spock smashes scissors"
}
}
else if(choice1==="lizard") {
if(choice2==="rock") {
return "Rock crushes lizard"
}
else if(choice2==="paper") {
return "Lizard eats paper"
}
else if(choice2==="scissors") {
return "Scissors decapitates lizard"
}
else {
return "Lizard poisons Spock"
}
}

else if (choice1==="Spock") {
if(choice2==="rock") {
return "Spock vaporizes rock"
} else if(choice2==="paper") {
return "Paper disproves spock"
} else if(choice2==="lizard") {
return "Lizard poisons Spock"
}
else {
return "Spock smashes scissors"
}
}
}
compare(userChoice, computerChoice)

I'm new to programming, so explain like I where a 5-year-old.


#2

Change you console.log to document.write and than put your code in a html file.
That should look like that here:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
    function yourFunction(){
     // your code
    }
</script>
</head>
<body>
<script type="text/javascript">
    yourFunction();
</script>
</body>
</html>