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.
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 />");
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.