Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Big
    Big is offline
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to show the change in a number

    I would like to know the javascript of how to show a change in a number.
    Example:

    Today

    Ranked 786

    Tommorow

    Ranked 779 -7

    How do I make it so that Javascript will change that for me by showing that the number has changed by -7 so I won't have to do it manually?

  • #2
    Regular Coder
    Join Date
    Dec 2004
    Location
    Jamaica
    Posts
    592
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Not exactly sure what you wanna do. But uhhhh I think "eval" might help you.

    alert(eval("700 - 5")); // will alert 695

    Possibly you could store the decrement in one value and the actual value in another.
    So you could probably do something like...

    var total = 700;
    var decrement = 5;
    eval(total + " - " + decrement); // forms the string "700 - 5" , hence givin 695
    I'm gonna find a way to download the internet if its the last thing I do...
    Prepare to bow down to me (or my grave) and call me almighty when the algorithm is finished

  • #3
    Big
    Big is offline
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well i want this page to show rankings and if a ranking is 787 but the next day its 779 i want the javascript to show the change (in this case -8) next to the ranking automatically.

    Ranking 779 -8
    Last edited by Big; 01-28-2008 at 06:30 PM.

  • #4
    Regular Coder
    Join Date
    Dec 2004
    Location
    Jamaica
    Posts
    592
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Big View Post
    Well i want this page to show rankings and if a ranking is 787 but the next day its 779 i want the javascript to show the change (in this case -8) next to the ranking automatically.

    Ranking 779 -8
    Not sure if you even need to use eval.
    Code:
    var todayRating = 779;
    var yesterdayRating = 787;
    var ratingDifference = ("Today\'s rating is: " + todayRating + " " + (todayRating - yesterdayRating);
    alert(ratingDifference); // Will prompt: "Today's rating is 779 - 8"
    I'm gonna find a way to download the internet if its the last thing I do...
    Prepare to bow down to me (or my grave) and call me almighty when the algorithm is finished

  • #5
    Big
    Big is offline
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    didn't work
    thanks anyway though

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,314
    Thanks
    203
    Thanked 2,564 Times in 2,542 Posts
    var todayRating = 779;
    var yesterdayRating = 787;
    var ratingDifference = ("Today\'s rating is: " + todayRating + " = a change of " + (todayRating - yesterdayRating) ) ; // missing bracket
    alert(ratingDifference); // Will prompt: "Today's rating is 779 - 8
    Last edited by Philip M; 01-28-2008 at 07:46 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •