var thing1 = prompt("what is a number")
var thing2 = prompt("what is a number")
alert(Math.min(thing1,thing2));
I am able to get the minimum of the two members.
How do I change this to give the average of the two numbers asked?
var thing1 = prompt("what is a number")
var thing2 = prompt("what is a number")
alert(Math.min(thing1,thing2));
I am able to get the minimum of the two members.
How do I change this to give the average of the two numbers asked?
Here's a function that gets an average:
function average(){
var a = arguments, l = a.length;
if(l){
for(var i=0,n=0; i<l; i++){
n += a[i];
}
return n/l;
}
return false;
}
// horrible idea to use prompt and alert
var prompt1 = prompt('enter a number');
var prompt2 = prompt('enter another number');
alert(average(prompt1, prompt2));