-7
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?

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256
  • 1
    Average means you need to add your numbers together and divide by how many numbers you added together. – StackSlave Oct 12 '16 at 23:36
  • There is no inbuilt average method in javascript. you need to write your own method.which is very straight forward ..This link wold help you of how u can do it better http://stackoverflow.com/questions/10359907/array-sum-and-average – Geeky Oct 12 '16 at 23:39
  • Try Googling "How do I get the average of two numbers". Hint: It doesn't involve taking their minimum. – Nic Oct 12 '16 at 23:40
  • I know what an average is.... I'm asking how I write the code to get that? I am using AppStudio. I'm trying to learn and I don't know how to do this on my own, aka why I came to this website!! – Maddie Cheasick Oct 12 '16 at 23:59
  • `(thing1+thing2)/2` if `thing1` and `thing2` are numeric types. – John Alexiou Oct 13 '16 at 00:02
  • Is this `JavaScript`? – John Alexiou Oct 13 '16 at 00:04

1 Answers1

0

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));
StackSlave
  • 10,613
  • 2
  • 18
  • 35