help me solve this simple problem

Discussion in 'JavaScript' started by judge0, Sep 3, 2008.

  1. #1
    i have around 6 var "256-512-1M.. and so on" which store in my database as value like "1-2-3 .. and so on"
    i want the code

    if the value "1" turn or appear 256

    if value "2" // // // 512

    if value "3" // // // 1M

    i try to solve more time but i failed

    plz help me
    Thx in advence
     
    judge0, Sep 3, 2008 IP
  2. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If I understand correctly, you need something like this:

    var new_value = value*256;
    
    if(new_value >= 1024)
       new_value = new_value/1024+'M';
    Code (markup):
     
    xlcho, Sep 4, 2008 IP
  3. Daemn

    Daemn Peon

    Messages:
    27
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    var obj = {1: "256K", 2: "512K", 3: "1M"};

    new_value = obj[value];
     
    Daemn, Sep 4, 2008 IP
  4. judge0

    judge0 Peon

    Messages:
    400
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #4
    i think this what i want
    
    var data = 2;
    var speed = ["256", "512", "1024", "2048", "4096"];
    var arrayi = data - 1;
    document.write(speed[arrayi]);
    
    Code (markup):
     
    judge0, Sep 4, 2008 IP