...

View Full Version : javascript beginner!!



university
07-30-2011, 04:16 AM
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!");
}

djh101
07-30-2011, 04:40 AM
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.

university
07-30-2011, 04:44 AM
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 :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum