|
the question is as follows:
Using JavaScript, write a script that inputs five numbers and determines and outputs HTML text that displays the number of negative numbers, the number of positive numbers, and the number of zeros input.
the code i have written is this:
=========================================
<HTML>
<HEAD>
<TITLE> HW2-QUESTION2</TITLE>
</HEAD>
<SCRIPT LANGUAGE ="JavaScript">
var negative=0,
positive=0,
zeros=0,
number=1,
count;
while (number<=5){
count= window.prompt( "enter a number","0");
if(count=="0")
zeros=zeros+1;
else if(count>0)
positive = positive+1;
else
negative=negative+1;
number= number+1;
}
document.writeln( "<H1>Count Results</H1>");
document.writeln("zeros: " + zeros +"<BR>positive:"
+positive+"<BR>negative:" + negative +);
</SCRIPT>
</HTML>
=========================================
there is something wrong with the code because it is not working..plz help me out..
|
|
|
1. all yuzer input is character. Yu gotta konvert tu numbers...
innumber=parseInt(inputchars);
2. Yu need sum wae tu stop ask for the input.
2.1 yu kan put in in a for loop tu duit
5 times.
2.2 or chek if input is null or all blank
tu stop program.
<Added>
oops...yu hav while loop
3. zero is positive.
4. yu left off the "{"...
if(sumthang){
stuff
}
<Added>
5. I rekmend better variabel names:
numloops
numpositiv
numneg
numzero
<Added>
6. if yu run with internet explorer, look down at bottom av skreen next the the start button.
If js see errer in yer kode if put up a "!" there
klik on it tu see wot it thank av yer kode.
<Added>
7. yu kan stop the loop if no input with
if(inputchar == ""){break}
|
|
|
|
|
|
|
// |