Skip to content
WJunction - Webmaster Forum

Javascruot Not Working Properly

Status
Not open for further replies.

KrøniiK

Experienced Member
671
2009
32
PHP:
//asks the user for a code letter then shows the manufacturing grade

var userInput = prompt ("Please enter your code letter here:", "");

if (userInput == "S" || "s")
{
document.write("Your manufacturing grade is Space Grade");
}

else if (userInput == "M" || "m")
{
document.write("Your manufacturing grade is Military Grade");
}

else if (userInput == "C" || "c")
{
document.write("Your manufacturing grade is Commercial Grade");
}

else (userInput == "T" || "t")
{
document.write("Your manufacturing grade is Toy Grade");
}



P.S "The Result I get if I put anything is

Your manufacturing grade is Space GradeYour manufacturing grade is Toy Grade.

I get nothing else... any letter i put or not... to remove the second part of it like not showing hte last part for the letter "T" i just place

else if on it and it works at the end, but again any letter number still gives me the first result only.
 

2 comments

lol first of all your conditional statements are wrong.
To compare a variable with two values you have to do it like:-
PHP:
( (userInput == 's' ) || (userInput == 'S' ) )

The second problem in your code is that u are putting a conditional statement with `else` :p (maybe u forgot what elseif is for :|)

And why dont u just convert userInput to lowercase and then compare :|
So your code should look like:-

PHP:
var userInput = prompt("Please enter your code letter here:", "").toLowerCase();

if (userInput == "s")
{
document.write("Your manufacturing grade is Space Grade");
}

else if (userInput == "m")
{
document.write("Your manufacturing grade is Military Grade");
}

else if (userInput == "c")
{
document.write("Your manufacturing grade is Commercial Grade");
}

else if (userInput == "t")
{
document.write("Your manufacturing grade is Toy Grade");
}

else 
{
document.write("You didnt enter a code letter.");
}
 
Status
Not open for further replies.

About the author

K
Experienced Member · Joined
671
Messages
32
Reactions
28
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom