Result Error same thing second JS problem !

Discussion in 'JavaScript' started by KrøniiK, Feb 4, 2011.

  1. #1
    //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");
    } 
    PHP:

    every time I try putting it to work I get the result of the first one "Your manufacturing grade is Space Grade" any letter or number I put is the same. I need help on what I am doing wrong here.
     
    KrøniiK, Feb 4, 2011 IP
  2. rainborick

    rainborick Well-Known Member

    Messages:
    424
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Your condition clauses are incorrect. You should use something like:
    
    if ((userInput == "S") || (userInput == "s")) {
    
    Code (markup):
    and would be simpler if you used:
    
    if (userInput.toUpperCase() == "S") {
    
    Code (markup):
     
    rainborick, Feb 4, 2011 IP
    KrøniiK likes this.
  3. KrøniiK

    KrøniiK Peon

    Messages:
    262
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks mate got it to work.
     
    KrøniiK, Feb 5, 2011 IP