Exercise 8


#1

Don't knw whts wrong with this :(. PLZ sm1 help.


#2

Can you please post code so we can find your problem? Thankyou


#3

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice <= 0.34) {
	computerChoice = "rock";
} 
else if(computerChoice <= 0.67) {
	computerChoice = "paper";
} 
else {
	computerChoice = "scissors";
} 

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

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";
    }
}
else if(choice1==="scissors"){
    if (choice2==="rock"){
        return "rock wins";
    }
    else{
        return "paper wins";
    }
}
}
compare(userChoice , computerChoice);

#6

Well these error messages are actually pretty good if you ignore the undefined part which doesn't make much sense. What is telling you is that you get "paper wins" when the inputs are scissors and papers. If you follow this in your code you can see that this is true. Unfortunately scissors has no chance to win in your game.


#7

@amanuel2- could you plz help me too with my code!???
send me ur id.


#8

Sure! Post the code here


#9

@amanuel2 need to help me with running this code on some web browser like chrome or firefox.
How do I do that??

i created a html file and this within script tags but what next????


#10

Install atom, then put your files there and then double click your html file in your folder and then it should work.


#11

whats atom?
And dont u think the code has console output.
so it wont appear on screen?


#12

What are you trying to do? Run your files in codecademy or browser? I mean are you trying to code your own stuff? Im confused.


#13

trying to run them on browser!!!!!!


#14

just running the same codecademy codeon browser.


#15

Just go to https://www.codecademy.com/learn/javascript and then run it there... What are you asking?


#16

i am trying to code my own stuff.
so trying the code given in codecademy ie the game on my browser.


#17

Ok then. You want to code in codecademy? If you do then just code your own stuff there... Whats wrong? You want me to check your game since it has an error?


#18

u arent getting me.
I just want to run that game on my browser and not through codecademy.
its running well in codecdemy but not when i use it for the browser.


#19

Ok @codesolver31872 pm me i have something in plan. Lets reduce noise here...


#20

the whole thing seems rather backwards at this point.


#21

Thanks, Hax. This was a big help. Due to the "undefined" part, I assumed it was a bug. But your breakdown solved it for me.

J