![]() |
Java Script Beginner. For Loop Question.
Hello, Been meaning to join this forum for a while but just now got around to it due to a problem I'm having. I was given an assignment to design a program that accepts five daily temperature readings and display the highest, lowest, and average temperatures. I'm supposed to use a For loop to take the five readings. I'm having trouble in figuring out how to use the data entered by the user to preform calculations on them. As in getting them from the user and storing them to use. So far this is the code I've gotten
Code:
<html> |
1. Don't use prompt() as it is intended for debugging only - use a form in your web page instead to collect the values.
2. Don't use document.write - that went out of use when Netscape 4 died as subsequent browsers support the far more powerful innerHTML call instead. If someone is actually teaching either of those then they need to take a beginners JavaScript class to learn how to write JavaScript for 21st century web browsers. To be able to advise how to set up a for loop to process the five input fields we will first need to see how you have defined the form. You can convert strings to numbers using either Number(str) or (+str) You can use Math.max() and Math.min() to get the maximum and minimum values. |
Quote:
|
Week 13 of a JavaScript course and you are only up to using for loops? Or does the course cover a number of web languages and you are just onto the small section of the course that attempts to cover JavaScript?
Which book is it? There have been one or two JavaScript books that I know of that were published after 2006 that still taught antiquated code like that but none that I know of that were published as recently as 2011. Here's how a prompt looks in some browsers now - note the checkbox for turning off JavaScript (some other browsers have the checkbox simply stop any further prompts from appearing instead so that the following code would run but using an empty string for the remaining inputs): http://javascriptexample.net/inc/prompt.gif |
The class is called "Program Design and Development". We only learn Java Script in it. Oh, that and some QBasic. Haha. Week 13 and yes, just now getting into For Loops.
This is the book we're using http://www.amazon.com/Principles-Pro...ith+javascript |
This will move you forward. I leave you to work out how to find the highest and lowest values in the array. Hint - set initial value of highest to -99999 and then loop through the array, if data[i] is greater than highest then highest = data[i].
Code:
<html>The book you mention is advertised at $87.32 . Surely that is a joke! |
Quote:
|
closing thread since it was getting hijacked, HeadSetJones please start another thread if you need further help.
|
| All times are GMT +1. The time now is 08:06 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.