Asked by Adam
I would like the function test to get the input from the user and display the like the counter function and to display if it passed or not.
var negatives =0;
var zeroes =0;
var positives=0 ;
function counter(array){
var i=0;
for(i=0;i<array.length;i++)
{
switch (true )
{
case (array[i] == 0) :
zeroes++;
break;
case (array[i] > 0) :
positives ++;
break;
case (array[i] < 0) :
negatives ++;
break;
}
}
return "Negatives = "+negatives+"\nZeroes = "+zeroes+"\nPositives = "+positives;
}
function show_prompt(){
var myIntArray = new Array(10);
var i=0;
for(i=0;i<10;i++){
var num = prompt("Please enter a number","Please enter a number");
myIntArray[i] = parseInt(num);
}
var output = counter(myIntArray);
alert (output);
}
function test() {
var myIntArray = new Array(3);
myIntArray [0]=-1;
myIntArray [1]=0;
myIntArray [2]=1;
counter(myIntArray);
if(zeroes ==1 && positives ==1 && negatives ==1) {
alert('Test passed');
}
else alert('Test Failed');
}
var negatives =0;
var zeroes =0;
var positives=0 ;
function counter(array){
var i=0;
for(i=0;i<array.length;i++)
{
switch (true )
{
case (array[i] == 0) :
zeroes++;
break;
case (array[i] > 0) :
positives ++;
break;
case (array[i] < 0) :
negatives ++;
break;
}
}
return "Negatives = "+negatives+"\nZeroes = "+zeroes+"\nPositives = "+positives;
}
function show_prompt(){
var myIntArray = new Array(10);
var i=0;
for(i=0;i<10;i++){
var num = prompt("Please enter a number","Please enter a number");
myIntArray[i] = parseInt(num);
}
var output = counter(myIntArray);
alert (output);
}
function test() {
var myIntArray = new Array(3);
myIntArray [0]=-1;
myIntArray [1]=0;
myIntArray [2]=1;
counter(myIntArray);
if(zeroes ==1 && positives ==1 && negatives ==1) {
alert('Test passed');
}
else alert('Test Failed');
}
Answers
There are no human answers yet.
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.