Simple prog but why doesn't it work??

Discussion in 'JavaScript' started by rudy111, Jan 2, 2012.

  1. #1
    Hello folks;

    See this simple script:

    var V="";
    var Tpe="";

    var Tpe=10;

    if (Tpe=10)
    {
    V1="nut";
    }

    if (Tpe=5)
    {
    V1="radio";
    }

    if (Tpe=6)
    {
    V1="Provider";
    }

    document.write(Tpe + " / " + V+ "<br />");

    When I excecute it, the answer = 6 / Provider.

    I has expected 10 / nut

    So what do I miss ???????

    Thanks in advance, Rudy
     
    rudy111, Jan 2, 2012 IP
  2. mmerlinn

    mmerlinn Prominent Member

    Messages:
    3,197
    Likes Received:
    819
    Best Answers:
    7
    Trophy Points:
    320
    #2
    You don't need the BLUE line.
    You need to fix the RED variables.

    Don't know if that will fix your problem or not, but it is a start.
     
    mmerlinn, Jan 2, 2012 IP
  3. rudy111

    rudy111 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    off course, stupid of me, thanks, Rudy
     
    rudy111, Jan 2, 2012 IP
  4. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #4
    your if statements are wrong..
    when comparing it should be double equal sign..
    using a single equal sign will assign the value to that variable even it is inside the if statement..

    it should be like this:
    
    var V="";
    var Tpe="";
    
    var Tpe=10;
    
    if ([COLOR="#FF0000"]Tpe==10[/COLOR])
    {
    V1="nut";
    }
    
    if ([COLOR="#FF0000"]Tpe==5[/COLOR])
    {
    V1="radio";
    }
    
    if ([COLOR="#FF0000"]Tpe==6[/COLOR])
    {
    V1="Provider";
    }
    
    document.write(Tpe + " / " + V+ "<br />");
    
    Code (markup):
     
    JohnnySchultz, Jan 3, 2012 IP
  5. rudy111

    rudy111 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Johnny;Thank you for your support! I am a newbee in Javascript, but i'm learning, i'm learning.....greetz, rudy
     
    rudy111, Jan 3, 2012 IP