James L James L - 4 months ago 6
HTML Question

How can I display the day of the week, (I have the highest value)?

How would I display the day, I have the highest value over the week but I need to match the highest value to the correct day of the week. If you have an idea please use jsfiddle or other program to show! Thanks!



<script>
function total() {
var th = Number(monday.value) + Number(tuesday.value) + Number(wednesday.value) + Number(thursday.value) + Number(friday.value) + Number(saturday.value) + Number(sunday.value);
alert("You gamed for " + th + " hours this week");



var ah = th / 7;
alert("Your average is " + ah + " hours this week");

var arr = [Number(monday.value), Number(tuesday.value), Number(wednesday.value), Number(thursday.value), Number(friday.value), Number(saturday.value), Number(sunday.value)]

var hh = 0;
var max = arr[0];

for(var i = 1;i < arr.length;i++) {
if(arr[i-1] < arr[i]) {
max = arr[i];
}
}

alert("Maximum hours you have gamed in one day is " + max);
}





button.onclick = total;
</script>

<!DOCTYPE html>
<html>
<link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico" />
<title>The Gaming Hours Quiz</title>
<body>
<h1>The Gaming Hours Quiz</h1>
</body>
<p>Welcome to the Gaming Hours Quiz. Please fill out the neccesary information correctly to get your true results</p>

<h3 id= "nametitle">What is your name?</h3>
<input id="name" type="letter" name="" value="type name here...">

<h3>How many hours have you gamed on Monday?</h3>
<input id="monday" type="number" name="" value="0">


<h3>How many hours have you gamed on Tuesday?</h3>
<input id="tuesday" type="number" name="" value="0">


<h3>How many hours have you gamed on Wednesday?</h3>
<input id="wednesday" type="number" name="" value="0">


<h3>How many hours have you gamed on Thursday?</h3>
<input id="thursday" type="number" name="" value="0">


<h3>How many hours have you gamed on Friday?</h3>
<input id="friday" type="number" name="" value="0">


<h3>How many hours have you gamed on Saturday?</h3>
<input id="saturday" type="number" name="" value="0">


<h3>How many hours have you gamed on Sunday?</h3>
<input id="sunday" type="number" name="" value="0">
<br>
<br>
<button id="button">Submit</button>

</html>




Answer

<script>
function total() {
	var th = Number(monday.value) + Number(tuesday.value) + Number(wednesday.value) + Number(thursday.value) + Number(friday.value) + Number(saturday.value) + Number(sunday.value);
	alert("You gamed for " + th + " hours this week");



var ah = th / 7;
alert("Your average is " + ah + " hours this week");

var arr = [Number(monday.value), Number(tuesday.value), Number(wednesday.value), Number(thursday.value), Number(friday.value), Number(saturday.value), Number(sunday.value)]

var hh = 0;
var max = arr[0];
var days = ["Monday","Tuesday",...];
var dayOfMax = 0;

for(var i = 1;i < arr.length;i++) {
	if(arr[i-1] < arr[i]) {
  	max = arr[i];
    dayOfMax = i; // why not just get the index
  }
}

alert("Maximum hours you have gamed in one day is " + max);
alert("The day when you have gamed the maximum is " + days[dayOfMax]);
// 0 for Monday, 1 for Tuesday, 2 for Wednesday, and so on
}





button.onclick = total;
</script>
<!DOCTYPE html>
<html>
 <link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico" />
		<title>The Gaming Hours Quiz</title>
			<body>
				<h1>The Gaming Hours Quiz</h1>
			</body>
				<p>Welcome to the Gaming Hours Quiz. Please fill out the neccesary information correctly to get your true results</p>

		<h3 id= "nametitle">What is your name?</h3>
<input id="name" type="letter" name="" value="type name here...">				

		<h3>How many hours have you gamed on Monday?</h3>
<input id="monday" type="number" name="" value="0">


<h3>How many hours have you gamed on Tuesday?</h3>
<input id="tuesday" type="number" name="" value="0">


<h3>How many hours have you gamed on Wednesday?</h3>
<input id="wednesday" type="number" name="" value="0">


<h3>How many hours have you gamed on Thursday?</h3>
<input id="thursday" type="number" name="" value="0">


<h3>How many hours have you gamed on Friday?</h3>
<input id="friday" type="number" name="" value="0">


<h3>How many hours have you gamed on Saturday?</h3>
<input id="saturday" type="number" name="" value="0">


<h3>How many hours have you gamed on Sunday?</h3>
<input id="sunday" type="number" name="" value="0">
<br>
<br>
<button id="button">Submit</button>

</html>

Comments