PDA

View Full Version : Is It Possible To Create Such A Program?



Tseng
11-17-2008, 04:51 PM
Is it possible to prompt a user for a number and write out a list of numbers to the user picked number and also say next to each one whether it's odd or even?

clueful
11-18-2008, 12:26 AM
Is it possible to prompt a user for a number and write out a list of numbers to the user picked number and also say next to each one whether it's odd or even?Of course it's possible - your teacher wouldn't have asked you to do it otherwise.

You're welcome in advance.

Nile
11-18-2008, 12:42 AM
Here:


<script type="text/javascript">
var num = prompt('Feed me a number!','');
for(i=0;i<=num;++i){
if((i/2) == Math.round(i/2)){
document.write(i+" - Even<br />");
} else {
document.write(i+" - Odd<br />");
}
}
</script>

clueful
11-18-2008, 04:38 AM
for(var i=0; i<=num; ++i)
document.write(i + " - " + ( i&1 ? "Odd" : "Even") + "<br />");