Final step my code seems wrong, cant put it in netbean


<Below this line, add a link to the EXACT exercise that you are stuck at.>

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
I want to get this to work perfectly, i think i left out some parts. Also i want to be able to use a text editor to launch this in google chrome (outside of codeacademy) Can anyone help?


//user choice
var userChoice = prompt(“Do you choose rock, paper or scissors?”);
var compare = function(choice1,choice2) {
if (choice1===choice2) {
return(“The result is a tie!”);
} else if (choice1===“rock”){
if (choice2===“scissors”) {
return(“rock wins”);
} else {
return(“paper wins”);
} else if (choice1===“paper”){
if (choice2===“rock”) {
return(“paper wins”);
} else {
return(“scissors wins”);
//computer choice
var computerChoice = Math.random()
if (computerChoice < 0.34) {
computerChoice = “rock”;
} else if(computerChoice <= 0.67) {
computerChoice = “paper”
} else {
computerChoice = “scissors”
} console.log("Computer: " + computerChoice);

<do not remove the three backticks above>

Save your code in a local project folder named RPS (or some such) and give the file a name, 'rps.js`.

The game as written can only be played in the console, so open the file, copy it whole and paste it into the command line, and enter. Your code is missing a call to the compare() function. Add that line to the very end of the code.

console.log(compare(userChoice, computerChoice));

As soon as you enter the code it will run the prompt for user choice.

The browser’s console that is.

Alternative #2
Chrome and firefox can also execute stand-alone scripts, in chrome it’s in the dev console under sources->snippets, in firefox it’s shift f4 (or was it control? not alt anyway)

Alternative #3
Create a bare-bones html file that references your code


console.log('hello world');


<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <script src="code.js"></script>

Opening index.html would then run the code (provided that they are in the same directory)

And if you manage to find the sources in the dev console you can also add breakpoints to inspect the state of the program when it reaches a particular line.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.