-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
60 lines (52 loc) · 1.8 KB
/
script.js
File metadata and controls
60 lines (52 loc) · 1.8 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
// temperature conversion program
const textbox = document.getElementById("textbox");
const toFahrenheit = document.getElementById("toFahrenheit");
const toCelsius = document.getElementById("toCelsius");
const results = document.getElementById("results");
const reaction = document.getElementById("reaction");
let temperature;
function convert(){
if(toFahrenheit.checked){
temperature = Number(textbox.value);
temperature = (temperature *(9/5)) + 32 ;
results.textContent = temperature.toFixed(1) + " °F";
if (temperature > 71 && temperature < 99){
reaction.textContent = "😀";
}
else if(temperature <= 71 && temperature > 50 ){
reaction.textContent = "🤗";
}
else if(temperature < 50 ){
reaction.textContent = "🥶";
}
else if(temperature >= 99 && temperature < 109 ){
reaction.textContent = "😥";
}
else {
reaction.textContent = "🥵";
}
}
else if(toCelsius.checked){
temperature = Number(textbox.value);
temperature = (temperature-32 ) *(5/9);
results.textContent = temperature.toFixed(1) + " °C";
if (temperature > 22 && temperature < 37){
reaction.textContent = "😀";
}
else if(temperature <= 22 && temperature > 10 ){
reaction.textContent = "🤗";
}
else if(temperature < 10 ){
reaction.textContent = "🥶";
}
else if(temperature >= 37 && temperature < 43 ){
reaction.textContent = "😥";
}
else {
reaction.textContent = "🥵";
}
}
else{
results.textContent = "Select A Unit";
}
}