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 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2011
    Posts
    18
    Thanks
    2
    Thanked 0 Times in 0 Posts

    javascript beginner!!

    is this code right its supposed to be a code that prompts the user for a number less than 100 and outputs only odd numbers less than or equal to the number entered by the user.for example if a user eneters the number 10 you should display 1,3,5,7,9 to the browser window?...im not sure if i have done it right..i gave it a go though!


    var input = prompt("Enter a number less than 100:", "10");
    if( input <= 100){

    nbsp; for (var i = 1, i <= input, i++2){
    nbsp; document.write(i", ");
    nbsp; }

    }else{
    nbsp; alert(input + " is not less than 100!");
    }

  • #2
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    616
    Thanks
    48
    Thanked 65 Times in 65 Posts
    inside the for loop your statements should be separated by semi-colons rather than commas. There should also be a + after the i in your document.write statement. You can also remove all the nbsp;s, I don't really think those are necessary.
    "Yeah science!"
    Online Science Tools

  • Users who have thanked djh101 for this post:

    university (07-30-2011)

  • #3
    New Coder
    Join Date
    Jul 2011
    Posts
    18
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by djh101 View Post
    inside the for loop your statements should be separated by semi-colons rather than commas. There should also be a + after the i in your document.write statement. You can also remove all the nbsp;s, I don't really think those are necessary.
    thanks for thr help


  •  

    Posting Permissions

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