www.webdeveloper.com
Results 1 to 3 of 3

Thread: Need help with a conditional statements

  1. #1
    Join Date
    Nov 2013
    Posts
    1

    Need help with a conditional statements

    i am in need of help with writing a fairly simple piece of cod. basically i need to it take a number of yards and give me an output based on the number of yards.

    this is what i have so far...

    var yardsValue = document.write('<h2>' + 'The number of yards is '
    + Math.floor((Math.random()*100)+1) + '</h2>')
    {
    if (yardsValue > 0 && yardsValue < 10)
    {
    var yardsValue = 'The yards left to cover are'
    + yardsValue + 'and the play is to run the ball into the endzone'

    }
    else if (yardsValue >= 10 && yardsValue < 20)
    {
    var yardsValue = 'The yards left to cover are'
    + yardsValue + 'and the play is to throw the ball to a tight end'

    }
    else if (yardsValue >= 20 && yardsValue < 40)
    {
    var yardsValue = 'The yards left to cover are'
    + yardsValue + 'and the play is to throw the ball to a wide reciever'

    }
    else if (yardsValue >= 40 && yardsValue < 100)
    {
    var yardsValue = 'The yards left to cover are'
    + yardsValue + 'and the play is to punt the ball into opposition territory'

    }
    else if (yardsValue == 0 || yardsValue == 100)
    {
    alert('Invalid yards value entered')
    }

    alert(' ' + yardsValue)

    }

  2. #2
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    eh, doesn't look like homework...

    Code:
    var yardsValue = Math.floor((Math.random() * 100) + 1);
    
    document.write('<h2>' + 'The number of yards is ' + yardsValue + '</h2>');
    
    if (!yardsValue     ) {yardsValue = 'Invalid yards value entered';} else
    if (yardsValue <  10) {yardsValue = 'The yards left to cover are ' + yardsValue + ' and the play is to run the ball into the endzone';} else
    if (yardsValue <  20) {yardsValue = 'The yards left to cover are ' + yardsValue + ' and the play is to throw the ball to a tight end';} else
    if (yardsValue <  40) {yardsValue = 'The yards left to cover are ' + yardsValue + ' and the play is to throw the ball to a wide reciever';} else
    if (yardsValue < 100) {yardsValue = 'The yards left to cover are ' + yardsValue + ' and the play is to punt the ball into opposition territory';} else
                          {yardsValue = 'Invalid yards value entered';}
    
    alert(yardsValue);
    Last edited by bionoid; 11-04-2013 at 12:23 PM.

  3. #3
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,674
    it will be nice to count % of 'y' and 'V' in this code ))

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles