-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
141 lines (133 loc) · 5.36 KB
/
Copy pathindex.html
File metadata and controls
141 lines (133 loc) · 5.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<!DOCTYPE html>
<html>
<head>
<script>
function ToFahrenheit(inV,inUnit){
if( inUnit == 'celsius'){
return (inV * 9/5) + 32;
}
if( inUnit == 'kelvin'){
return (inV-273.15) * 9/5 + 32 ;
}
if( inUnit == 'rankine'){
return inV-459.67;
}
}
function ToKelvin(inV,inUnit){
if( inUnit == 'celsius'){
return inV + 273.15;
}
if( inUnit == 'fahrenheit'){
return (inV-32) * 5/9 + 273.15;
}
if( inUnit == 'rankine'){
return inV *5/9;
}
}
function ToCelsius(inV,inUnit){
if( inUnit == 'fahrenheit'){
return (inV-32) * 5/9;
}
if( inUnit == 'kelvin'){
return inV-273.15 ;
}
if( inUnit == 'rankine'){
return (inV - 491.67) * 5/9;
}
}
function ToRankine(inV,inUnit){
if( inUnit == 'fahrenheit'){
return inV +459.67;
}
if( inUnit == 'kelvin'){
return inV*1.8 ;
}
if( inUnit == 'celsius'){
return inV * 9/5 + 491.67 ;
}
}
function calResponse(i) {
console.log("Step 1");
var inputNValue=document.getElementById("inputNValue"+i).value;
var inputUnit=document.getElementById("inputUnit"+i).value;
var targetUnit=document.getElementById("targetUnit"+i).value;
var studentResp=document.getElementById("studentResp"+i).value;
var unitOfMeasure = ['fahrenheit','celsius','kelvin','rankine'];
console.log("Step 3");
if(isNaN(inputNValue)){
document.getElementById("ans"+i).innerText="invalid";
return;
}
console.log("Step 2");
if(isNaN(studentResp)){
document.getElementById("ans"+i).innerText="invalid";
return;
}
console.log("Step 3");
if(unitOfMeasure.indexOf(inputUnit.trim())<0){
document.getElementById("ans"+i).innerText="invalid";
return;
}
console.log("Step 4");
if(unitOfMeasure.indexOf(targetUnit.trim())<0){
document.getElementById("ans"+i).innerText="invalid";
return;
}
var calValue=0;
if( targetUnit.trim().toLowerCase() == "fahrenheit"){
calValue=ToFahrenheit(inputNValue,inputUnit.trim().toLowerCase());
}
if( targetUnit.trim().toLowerCase() == "celsius"){
calValue=ToCelsius(inputNValue,inputUnit.trim().toLowerCase());
}
if( targetUnit.trim().toLowerCase() == "kelvin"){
calValue=ToKelvin(inputNValue,inputUnit.trim().toLowerCase());
}
if( targetUnit.trim().toLowerCase() == "rankine"){
calValue=ToRankine(inputNValue,inputUnit.trim().toLowerCase());
}
if( studentResp == calValue ){
document.getElementById("ans"+i).innerText="correct";
} else {
if(parseFloat(studentResp).toFixed(2)==parseFloat(calValue).toFixed(2)){
document.getElementById("ans"+i).innerText="correct";
} else {
document.getElementById("ans"+i).innerText="incorrect";
}
}
}
</script>
</head>
<body>
<table>
<tr>
<td> Input Numerical value</td>
<td> Input Unit of Measure</td>
<td> Target Unit of Measure</td>
<td> Student Response</td>
<td> output </td>
</tr>
<tr>
<td> <input type="text" id="inputNValue1" onChange="calResponse(1)" /></td>
<td> <input type="text" id="inputUnit1" onChange="calResponse(1)"></td>
<td> <input type="text" id="targetUnit1" onChange="calResponse(1)"></td>
<td> <input type="text" id="studentResp1" onChange="calResponse(1)"></td>
<td> <div id="ans1"></div> </td>
</tr>
<tr>
<td> <input type="text" id="inputNValue2" onChange="calResponse(2)"></td>
<td> <input type="text" id="inputUnit2" onChange="calResponse(2)"></td>
<td> <input type="text" id="targetUnit2" onChange="calResponse(2)"></td>
<td> <input type="text" id="studentResp2" onChange="calResponse(2)"></td>
<td> <div id="ans2"></div> </td>
</tr>
<tr>
<td> <input type="text" id="inputNValue3" onChange="calResponse(3)"></td>
<td> <input type="text" id="inputUnit3" onChange="calResponse(3)"></td>
<td> <input type="text" id="targetUnit3" onChange="calResponse(3)"></td>
<td> <input type="text" id="studentResp3" onChange="calResponse(3)"></td>
<td> <div id="ans3"></div> </td>
</tr>
</table>
</body>
</html>