Switch statement 4 problem


#1

What is wrong
Error: missing ) after argument
var Health = 15;
var DarkHealth = 20;
var damage = 0;
var user = prompt("What attak should I do(magic,sword,potion").toUpperCase()
switch(user){
case 'SWORD' :
if (Math.floor(Math.random()*2 === false)){
console.log( DarkHealth - 8);
confirm("Critical Hit! Dark Health is damaged");
console.log( Health - 5);
}
else
{
console.log( DarkHealth - 6);
confirm("DarkHealth is damaged");
console.log( Health - 5);
}
break;
case 'MAGIC' :
console.log( Dark Health - 4);
confirm("You reduced Dark Health damage for one turn, Dark Health is damaged");
console.log( Health - 3);
break;
case 'POTION' :
console.log (Health + 10);
confirm("You healed yourself");
console.log( Health - 5);
break;
default :
console.log( Health - 8);
confirm("DarkHealth charged at you and you were unprepared");
};
thanks in advanced


#2

As the error reads, missing ) after argument. Count the parens in the above.


#3

okay I changed it
prompt("What attack should I do(magic,sword,potion")
still says the same thing


#4

Count the opening parens, 2. Now count the closing parens, 1. Add one to the very end, just before the toUpperCase() method call.


#5

prompt("What attack should I do(magic,sword,potion")) like this


#6

Yes. Now the prompt() argument is properly enclosed. However, on closer examination we can see where the real problem is. One of the parens is meant to be inside the quotes.


#7

prompt("What attack should I do (magic,sword,potion)")).toUpperCase() Fixed\
SyntaxError: Unexpected token )
I don't know why


#8

Remove the extra ) that you just added in. There should be one inside the quotes, and one outside.

You can avoid confusion in future by not using parens in the text. Use [,,,] instead so they stand out and don't look like code.

prompt("What attack should I do [magic,sword,potion]").toUpperCase()

#9

prompt("What attak should I do (magic,sword,potion)").toUpperCase()
Fixed
SyntaxError: missing ) after argument list


#10

prompt("What attack should I do [magic,sword,potion]").toUpperCase()
SyntaxError: missing ) after argument list
I am confused why I isn't working


#11

This is my code Now
var Health = 15;
var DarkHealth = 20;
var damage = 0;
var user = prompt("What attak should I do [magic,sword,potion]").toUpperCase()
switch(user){
case 'SWORD' :
if (Math.floor(Math.random()*2 === false)){
console.log( DarkHealth - 8);
confirm("Critical Hit! Dark Health is damaged");
console.log( Health - 5);
}
else
{
console.log( DarkHealth - 6);
confirm("DarkHealth is damaged");
console.log( Health - 5);
}
break;
case 'MAGIC' :
console.log( Dark Health - 4);
confirm("You reduced Dark Health damage for one turn, Dark Health is damaged");
console.log( Health - 3);
break;
case 'POTION' :
console.log (Health + 10);
confirm("You healed yourself");
console.log( Health - 5);
break;
default :
console.log( Health - 8);
confirm("DarkHealth charged at you and you were unprepared");
};


#12

Should I start over and try something else


#13

No. Suggest stay with the problem until it is solved.

The problem with the above is the parenthesis is on the wrong side of the equality.

Math.floor(Math.random()*2) === false

Keep looking for little problems like this. I'm satisfied the first problem is solved.


#14

if (Math.floor(Math.random()*2) === false
{
SyntaxError: Unexpected token {
Little by little We are getting closer to solving this


#15

Notice that above I only showed the expression that is inside the if condition. Add a parenthesis after false to close the if condition;

if ()

if (Math.floor(Math.random()*2) === false)

And that is why we must stick with it. Become an expert at finding and repairing bracket issues. They are the number one cause of errors.


#16

if (Math.floor(Math.random()*2) === false);
{
SyntaxError: Unexpected token else
do we need a semicolon after false)


#17

if I put no semicolon It shows this
SyntaxError: missing ) after argument list


#18

No semi-colon in an if statement. Only enclosed statements get a semi-colon.

if () {}
else if () {}
else {}

Sooner or later you will discover that false is not the value we need to compare. 0 and 1 are the output of the Math expression.


#19

so true instead of false


#20

What should I do to fix SyntaxError: missing ) after argument list