Keeps giving me syntax error


/*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"


keeps saying unexpected end of input


If you would like a answer to a syntax error problem, at least bother to format it correctly. You need to do your regular indenting, taking time as they don't copy and paste well. On top of this, add another four spaces, or highlight and press TAB. Nobody will be able to answer your problem, as the the issue may be in your indenting! I don't really see a problem, so look over this.

Good luck, EpicGeeth


@epicgeeth, not everyone on the forums is a coding guru or knows exactly how to format there code.

console.log("It's best to be supportive!");

when (peopleDontKnow) {
    //How to format!

All it takes is a little bit of patience. This is still a fairly new forum, so new members will not know everything right away.


i didnt put that there.when i went to this problem that was there already. in the instructions it says to leave it be. then in #8 or 9 it says to remove them.


Im new to coding so that is why I asked. I thought spaces didnt matter as long as you used the correct characters and correct order of your characters.


That is the closing of a block comment. In the exercise 1-4 you build the choices but as they aren't important for the building of the compare function they are kept as comments on top of the code.


Remember that at the end of functions you need to have an ending semi-colon " ; " so just add a semi-colon after your last bracket and that should get things settled for you!

@haxor789, Yes, I realized this just recently. Thank you though.


The chances the indentation really cause a problem in JS are pretty low that is more of a python thing, still it enormously helps to find an error quick if the code is well formatted. An easy to use site for doing so is But in the end getting used to doing it on the fly is probably the best way. And for formatting code as code there are either CTRL+K, or the </> button as well as [code][/code], 4 spaces before the line you want to be shown as code and probably even more ways. So if you see it maybe give some advices how to use this forum.

The problem is probably a missing } to close the function. Unexpected end of input often means that something is still open (missing a closing thing).

PS: A really nice way to write code is also by wrapping it in 3 backticks

``` code ```

because then the code is shown with syntax highlighting as you can see in OPs code.


Was bored so tried to figure out what was wrong with your code.

On your very last statement...

    else if (choice1 === "paper") {
                if (choice2 === "rock") {
                    return "paper wins";
                } else {
                    return "scissors wins" **//SEMI COLON IS NEEDED HERE**

So to clarify...
You are missing one semi colon at the end of the 'return scissors wins' and one curly bracket