Exercise 8


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


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


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" ;
        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";
        return "paper wins";
compare(userChoice , computerChoice);


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.


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


Sure! Post the code here


@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????


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


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


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.


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


just running the same codecademy codeon browser.


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


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


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?


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.


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


the whole thing seems rather backwards at this point.


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.