Soldato
Right, i've never used javascript before, so I thought i'd try a few simple scripts. Apart from the fact that IE is being really annoying and disabling the scripts upon loading the page, I can't get a simple function to work that calculates the average of 4 ages. Should be really easy right?!?!?
The result it come with is
'The average age of the students is NaN'
wtf???
Edit: Ok so it means 'Not a Number' apparently, so how does one convert a string to a numeric value in javascript
Code:
<HTML>
<SCRIPT>
function avgAge( a, b, c, d ) {
plaintxt = window.open("","plain","WIDTH=600,HEIGHT=300")
plaintxt.document.open("text/plain")
pdw = plaintxt.document.write
avg = (a+b+c+d)/4
pdw(' The average age of the students is ' + avg)
}
</SCRIPT>
<BODY>
<FORM onSubmit = "avgAge( this.student1, this.student2, this.student3, this.student4 )">
Age of student 1: <input type="text" name="student1"> <br>
Age of student 2: <input type="text" name="student2"> <br>
Age of student 3: <input type="text" name="student3"> <br>
Age of student 4: <input type="text" name="student4"> <br>
<input type="submit">
</FORM>
</BODY>
</HTML>
The result it come with is
'The average age of the students is NaN'
wtf???
Edit: Ok so it means 'Not a Number' apparently, so how does one convert a string to a numeric value in javascript
Last edited: