Same oldfag here, what the fuck is wrong with my code?
var max = 0
var min = 20
var sum
var average
for(i = 0; i < 2; i++)
{
n = window.prompt("How much was the temperature?: ")
sum = sum + n
average = sum / 2
if (n > max) {
max = n
}
if (n < min) {
min = n
}
}
alert("The average temperature is: " + average)
alert("The max temperature is: " + max)
alert("The min temperature is: " + min)
Is saying "The average temperature is: NaN", I know I need to use parseInt, but I don't know where, and yes newfags, i am a noob programmer :)
Lmao are you actually 11 years old? There's so many fundamental errors with this it's hilarious. To fix your NaN issue, you need to initialize the sum variable. Right now you havevar sum
And you need to set it to a value like 0. Your program is adding something that doesn't exist to a number you just asked the user for. Change the sum declaration to this:var sum = 0;
Don't get me started on how bad literally everything else is...
>>57025498
Oh my fucking god, im a fucking retarded.
>>57025454sum = sum + n
You're adding something undefined and n. This will return NaN.window.prompt("How much was the temperature?: ")
The prompt functions returns a string and not a number.
>>57025633
Also, using semicolons at the end of each line makes it look better and also makes it easier to read.
>>57025633
Well anon, how much was the temperature??? :")
>>57026051
Very :")