Unexpected token {?

project

#1

I'm working on a interactive story but ive encountered a problem.

var i = 0
var user = prompt("what's your name","name").toLowerCase()
var user = user.toLowerCase(); user = user.charAt(0).toString(user.charAt(0)).toUpperCase()+user.substring(1); 
alert("your name is " + user)
story = prompt("You are walking through the forest when you encounter an angry goblin, he wants to kill you, you have a knife, 15 gold and are in the mood to run. what do you do, do you pay, run or fight!","PAY, RUN or FIGHT")
if (story = "PAY") {
    var pay = prompt("how much? - remember, you only have 15 gold","just write the number") {if (isNaN(pay) = false) {if (pay < 6) {alert(user": Here is "pay" gold, just don't kill me!" "Goblin: Are yeh hoking meh? "pay" gold arent nuthin" "SLICE!") alert("Game Over, You made the goblin think you were pranking him, don't worry though, he loses all his money and feels realy sorry for you, he even puts a rose on your grave")}
    }
    }
}else{
    




}

why does this code say "SyntaxError: Unexpected token {"


#2

It's because of the { in


#3

ok thats good and all but i got a new problem

var i = 0
var user = prompt("what's your name","name").toLowerCase()
var user = user.toLowerCase(); user = user.charAt(0).toString(user.charAt(0)).toUpperCase()+user.substring(1); 
alert("your name is " + user)
story = prompt("You are walking through the forest when you encounter an angry goblin, he wants to kill you, you have a knife, 15 gold and are in the mood to run. what do you do, do you pay, run or fight!","PAY, RUN or FIGHT")
if (story = "PAY") {
    var pay = prompt("how much? - remember, you only have 15 gold","just write the number") 
    if (isNaN(pay) = false) {if (pay < 6) {alert(user": Here is "pay" gold, just don't kill me!" "Goblin: Are yeh hoking meh? "pay" gold arent nuthin" "SLICE!") alert("Game Over, You made the goblin think you were pranking him, don't worry though, he loses all his money and feels realy sorry for you, he even puts a rose on your grave")}
    }
    }
}else{}

SyntaxError: missing ) after argument list

#4

= means affectation
=== means equal

Try to correct the if statement then tell me what happen.


#5

ok it still doesnt work

var i = 0
var user = prompt("what's your name","name").toLowerCase()
var user = user.toLowerCase(); user = user.charAt(0).toString(user.charAt(0)).toUpperCase()+user.substring(1); 
alert("your name is " + user)
story = prompt("You are walking through the forest when you encounter an angry goblin, he wants to kill you, you have a knife, 15 gold and are in the mood to run. what do you do, do you pay, run or fight!","PAY, RUN or FIGHT")
if (story === "PAY") {
    var pay === prompt("how much? - remember, you only have 15 gold","just write the number") 
    if (isNaN(pay) === false) {if (pay < 6) {alert(user": Here is "pay" gold, just don't kill me!" "Goblin: Are yeh hoking meh? "pay" gold arent nuthin" "SLICE!") alert("Game Over, You made the goblin think you were pranking him, don't worry though, he loses all his money and feels realy sorry for you, he even puts a rose on your grave")}
    }
    }
}else{
    




}
////syntax error unexpected token "==="

#6

You declare 3 variables with the same name. The last one will overwrite the others.
According to what you are trying to do, here is the good syntaxe:

var i = 0;
var user = prompt("what's your name","name").toLowerCase(); //??
var user = user.toLowerCase(); //??
var user = user.charAt(0).toString(user.charAt(0)).toUpperCase()+user.substring(1); //??
alert("your name is " + user);
var story = prompt("You are walking through the forest when you encounter an angry goblin, he wants to kill you, you have a knife, 15 gold and are in the mood to run. what do you do, do you pay, run or fight! \n PAY, RUN or FIGHT");
if (story === "PAY") {
    var pay = prompt("how much? - remember, you only have 15 gold \n just write the number") ;
    if (isNaN(pay) === false) {
             if (pay < 6) {
                        alert(user + ": Here is " + pay + " gold, just don't kill me!" "Goblin: Are yeh hoking meh? " + pay + " gold arent nuthin \n SLICE!");
                        alert("Game Over, You made the goblin think you were pranking him, don't worry though, he loses all his money and feels realy sorry for you, he even puts a rose on your grave");
            } //end if
    } //end if
else{}

#7

It must be affectation not equality.:slight_smile:


#8

ok first off thank you for this this is great
secondly the three user variables makes your name all lowercase with the first letter uppercase (u'd not believe how long it took to make it)
thirdly it still says missing ) after arguments list?


#9

My fault

Try
" gold arent nuthin \n SLICE!"


#10

Im really sorry about troubling you with this but it still doesnt work

ps heres my current code:

var i = 0
var user = prompt("what's your name","name").toLowerCase()
var user = user.toLowerCase(); user = user.charAt(0).toString(user.charAt(0)).toUpperCase()+user.substring(1); 
alert("your name is " + user)
story = prompt("You are walking through the forest when you encounter an angry goblin, he wants to kill you, you have a knife, 15 gold and are in the mood to run. what do you do, do you pay, run or fight!","PAY, RUN or FIGHT")
if (story === "PAY") {
    var pay = prompt("how much? - remember, you only have 15 gold","just write the number") 
    if (isNaN(pay) === false) {if (pay < 6) {alert(user": Here is "pay" gold, just don't kill me!" "Goblin: Are yeh jhoking meh? "pay" gold arent nuthin \n SLICE!") alert("Game Over, You made the goblin think you were pranking him, don't worry though, he loses all his money and feels realy sorry for you, he even puts a rose on your grave")}
    }
    }
}else{
    




}

#11

its the same syntax error btw


#12

You may want to add toUpperCase() or the if condition on the next line won't execute. Then look at @konaesan's syntax corrections to your code and apply them.


#13

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.