Code correct but same error mssg wont go away - help!


#1

my code seems correct as I compared it to other's code here, but I still get the same rror message I cannot get rid of... any clues?
here's my code: 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 win"; }
}
else if (choice1 === "rock"){
if (choice2 === "paper"){
return "paper wins";
}
else{
return "rock wins";}

}

};


#2

Please post code this format. Thankyou


#3

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 win"; }
}
else if (choice1 === "rock"){
if (choice2 === "paper"){
return "paper wins";
}
else{
return "rock wins";}

}

};


#4

well... it formats it like that even when pressing 3 keys...


#5

Just select over your code and hit CTRL+SHIFT+C . After its formatted by jsbeautifier as i listed above in my topic

If that dosent work try hitting the code formatter above on the toolbar section where it says </>


#6

it looks ok when i paste, but on preview it doesnt


#7

?

i pressed the 3 ` but when exactly should i press them?


#8

Ok so do this paste your code in, then hit the </> above the toolbar where there are the buttons that make your text bold, give you hyperlinks, emotes, etc... Then it should work.


#9
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 win"; }
    }
    else if (choice1 === "rock"){
        if (choice2 === "paper"){
        return "paper wins";
    }
    else{
        return "rock wins";}

    }
};

#10

You have two else ifs concerning rock but none concerning scissors. The syntax is correct although it would be better readable if you could format your code like in the first else if (one level of indentation per new block of code {}).


#11

i keep getting that same message from the very beginning : Your compare function does not return 'The result is a tie!' when there is a tie.
Here is the corrected code:

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

sorry, the right formATTING DOES NOT WORK AGAIN! driving me crazy. the issue is that i keep getting the same above message.


#12

You need an ! at the end of the message. Also you can press the edit button to see how I formatted your code.


#13

oh wow, the !
Thank you!
:slightly_smiling: