Thursday
December 18, 2014

Homework Help: Javascript

Posted by Adam on Tuesday, November 22, 2011 at 11:53pm.

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');
}

Answer this Question

First Name:
School Subject:
Answer:

Related Questions

Javascript - How do take this following javascript and put in external ...
Programming - Design a program in pseudocode that calculates the amount of money...
Programming - Design a program in pseudocode that calculates the amount of money...
Javascript - I need help these javascript exericses: Input: A text string, using...
JavaScript - I need help these javascript exericses: Input: A text string, using...
Programming - Write a pseudocode program that asks the user for an integer ...
Engineering:Digital Design - Information given: 1) 2 X 8-bits input A and B 2) ...
programmning code - Is this code right? Declare Integer days, counter = 1 ...
JAVASCRIPT - Start button won't work for a scolling marquee. Below is the ...
Programming Logic - I need help creating a program to display the integers from ...

Search
Members