- Notifications
You must be signed in to change notification settings - Fork 27.3k
/
Copy pathsimple-else-if.html
43 lines (38 loc) · 1.54 KB
/
simple-else-if.html
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
<!DOCTYPE html>
<htmllang="en-US">
<head>
<metacharset="utf-8">
<metaname="viewport" content="width=device-width">
<title>Simple else if example</title>
</head>
<body>
<labelfor="weather">Select the weather type today: </label>
<selectid="weather">
<optionvalue="">--Make a choice--</option>
<optionvalue="sunny">Sunny</option>
<optionvalue="rainy">Rainy</option>
<optionvalue="snowing">Snowing</option>
<optionvalue="overcast">Overcast</option>
</select>
<p></p>
<script>
constselect=document.querySelector('select');
constpara=document.querySelector('p');
select.addEventListener("change",setWeather);
functionsetWeather(){
constchoice=select.value;
if(choice==='sunny'){
para.textContent='It is nice and sunny outside today. Wear shorts! Go to the beach, or the park, and get an ice cream.';
}elseif(choice==='rainy'){
para.textContent='Rain is falling outside; take a rain coat and a brolly, and don\'t stay out for too long.';
}elseif(choice==='snowing'){
para.textContent='The snow is coming down — it is freezing! Best to stay in with a cup of hot chocolate, or go build a snowman.';
}elseif(choice==='overcast'){
para.textContent='It isn\'t raining, but the sky is grey and gloomy; it could turn any minute, so take a rain coat just in case.';
}else{
para.textContent='';
}
}
</script>
</body>
</html>