BullyWiiHacks
Welcome dear guest! Very Happy

To start posting and being part of the BWH community, you simply need to register an account or log into an existing one.

If you do not wish to register at all, that's fine but there will be more advertisements. :/

You can probably see and download most content provided for regular members even without an account.

Your contributions will be greatly appreciated though, give it a shot and register today! thumbsup

Join the forum, it's quick and easy

BullyWiiHacks
Welcome dear guest! Very Happy

To start posting and being part of the BWH community, you simply need to register an account or log into an existing one.

If you do not wish to register at all, that's fine but there will be more advertisements. :/

You can probably see and download most content provided for regular members even without an account.

Your contributions will be greatly appreciated though, give it a shot and register today! thumbsup
BullyWiiHacks
Would you like to react to this message? Create an account in a few clicks or log in to continue.
BullyWiiHacks

Gaming, Modding & Programming

Important reminders:

- Click *HERE* for advanced forum search or check out the text field below on the front page for Google before posting
- NO support via private message (use the forum)
- Write meaningful topic titles
Site Translation
Latest topics
» Dropped Out of College to Pursue Web Dev and Life Pursuits in General
[Help]JavaScript Unexpected end of input Empty4/7/2024, 2:34 pm by SnB@BWH

» Bully Made It Into a BIG Video 400K Views
[Help]JavaScript Unexpected end of input Empty4/7/2024, 6:58 am by Bully@WiiPlaza

» Wii Play Tanks
[Help]JavaScript Unexpected end of input Empty3/24/2024, 2:46 pm by helpmeout

» [Bypass Paywalls] (Global) @magnolia1234 - GitLab
[Help]JavaScript Unexpected end of input Empty3/18/2024, 3:55 am by Seth@WiiPlaza

» [Download] Mary Shelley's Frankenhole
[Help]JavaScript Unexpected end of input Empty3/16/2024, 8:29 am by Seth@WiiPlaza

» Completely Custom Modded Controllers (Undetectable)
[Help]JavaScript Unexpected end of input Empty3/5/2024, 1:55 pm by Shadow@BWH

» (Zombies) Drink perks code?
[Help]JavaScript Unexpected end of input Empty3/5/2024, 1:24 pm by Shadow@BWH

» Die Rückkehr zu STEAM und WARFACE
[Help]JavaScript Unexpected end of input Empty3/2/2024, 3:54 am by Seth@WiiPlaza

» First person hand model change?
[Help]JavaScript Unexpected end of input Empty2/28/2024, 4:53 am by Ad3lamac611

» {RELEASE} Field Raider Firefox v1.72 by Seth@WiiPlaza
[Help]JavaScript Unexpected end of input Empty2/21/2024, 8:52 am by naxil

Search
 
 

Display results as :
 


Rechercher Advanced Search

April 2024
MonTueWedThuFriSatSun
1234567
891011121314
15161718192021
22232425262728
2930     

Calendar Calendar

Country Statistics
Free counters!

You are not connected. Please login or register

[Help]JavaScript Unexpected end of input

3 posters

Go down  Message [Page 1 of 1]

Shadow@BWH

Shadow@BWH
 
 

Okay so I'm just trying to make a rock paper sicors game and I keep getting a error no matter what I do it won't take my code. I went as far as coping the code they gave me in the hint and it still says it's wrong. Here's the code.

Code:
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";
    }

}


_________________
[Help]JavaScript Unexpected end of input BAjMdNS

SnB@BWH

SnB@BWH
Admin & Writer

I don't know JavaScript, but the error means you forgot to close the statement(s). Take a closer look at your semi-colons and brackets.


_________________
[Help]JavaScript Unexpected end of input Simple10

[Help]JavaScript Unexpected end of input LSTjSyDDiscord: SnB_BWH

Click HERE to earn free bitcoin, litecoin, dogecoin, and dash!

Win Free Bitcoins every hour!

Bully@WiiPlaza

Bully@WiiPlaza
 
 

If you format your code properly you might be able to tell where the mistake lies.

I did it for you:
http://pastebin.com/qLApgJ8g

Now it's clear to me what went wrong, also to you? Wink


_________________
[Help]JavaScript Unexpected end of input YBjg74I

Shadow@BWH

Shadow@BWH
 
 

I did it exactly like that I copied it into it and it still gives me the same error. I'm wondering if it's a bug in the program. I clear up one issue and it just gives me another. It starts you off with this.

Code:
var compare = function(choice1, choice2) {
    if(choice1 === choice2) {
        return "The result is a tie!";
    }
};

So adding to it it would be this

Code:
 } else if (choice1 === "rock")
    {
        if (choice2 === "scissors")
        {
            return "rock wins";
        } else
        {
            return "paper wins";
        }
    }

But it won't take the }; at the end of the first part and it gives you this.

SyntaxError: Unexpected token }

So I get rid of the extra part that is giving the error.

https://i.imgur.com/Ae2e2rX.png

and then it gives me this error

SyntaxError: Unexpected token else

The code is exactly how the person who gave it is.

Code:
if(choice1 === choice2) {
    return "The result is a tie";
}

else if(choice1 === "rock") {

    if(choice2 === "scissors") {
        return "rock wins";
    }
    else {
        return "paper wins";
    }

}

I'm absolutely astounded and baffled by it.



Last edited by Shadow@BWH on 12/6/2014, 1:05 pm; edited 1 time in total


_________________
[Help]JavaScript Unexpected end of input BAjMdNS

Bully@WiiPlaza

Bully@WiiPlaza
 
 

I didn't fix the code, I just formatted it for you to see better what's wrong.


_________________
[Help]JavaScript Unexpected end of input YBjg74I

Shadow@BWH

Shadow@BWH
 
 

I added to my last comment. Wait..... I left a bracket open didn't I....

and just like that I fixed it. Thanks Bully Razz I feel really dumb when I do stuff like this.

Code:
 var compare = function (choice1, choice2) {
     if (choice1 === choice2) {
         return "The result is a tie!";
     }
 };
 if (choice1 = "rock") {
     if (choice2 = "scissors") {
         console.log("rock wins");
     } else {
         console.log("paper wins");
     }
 }


_________________
[Help]JavaScript Unexpected end of input BAjMdNS

Bully@WiiPlaza

Bully@WiiPlaza
 
 

Exactly, a closing bracket was missing. Very Happy


_________________
[Help]JavaScript Unexpected end of input YBjg74I

SnB@BWH

SnB@BWH
Admin & Writer

I hate using languages that uses brackets or semi-colons because 90% of the time the error(s) you get are because of a semi-colon or bracket. The IDE should automatically correct it for you, but then what do you learn? lol


_________________
[Help]JavaScript Unexpected end of input Simple10

[Help]JavaScript Unexpected end of input LSTjSyDDiscord: SnB_BWH

Click HERE to earn free bitcoin, litecoin, dogecoin, and dash!

Win Free Bitcoins every hour!

Bully@WiiPlaza

Bully@WiiPlaza
 
 

shitnbitch@BWH wrote:I hate using languages that uses brackets or semi-colons because 90% of the time the error(s) you get are because of a semi-colon or bracket. The IDE should automatically correct it for you, but then what do you learn?  lol
It doesn't know how to correct syntax errors but it can show you where (approximately) an error lies because when it compiles it gets stuck somewhere close to the error. Eclipse does a good job in highlighting the spot:
[Help]JavaScript Unexpected end of input Eclips10

Mostly it's really easy to fix mistakes then:
[Help]JavaScript Unexpected end of input Eclips11


_________________
[Help]JavaScript Unexpected end of input YBjg74I

Shadow@BWH

Shadow@BWH
 
 

Ya I normally use jsfiddle to test the codes to make sure there working. Sometimes I just go full idiot and can't see what's in front of me.


_________________
[Help]JavaScript Unexpected end of input BAjMdNS

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum