-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
35 lines (30 loc) · 1021 Bytes
/
script.js
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
document.addEventListener('DOMContentLoaded', () => {
const form = document.getElementById('fruitForm');
const result = document.getElementById('result');
form.addEventListener('submit', (event) => {
event.preventDefault(); // Prevents the form from submitting the traditional way
const numberInput = document.getElementById('numberInput').value;
const number = parseInt(numberInput, 10);
let fruit;
switch (number) {
case 1:
fruit = 'Apple';
break;
case 2:
fruit = 'Banana';
break;
case 3:
fruit = 'Cherry';
break;
case 4:
fruit = 'Date';
break;
case 5:
fruit = 'Elderberry';
break;
default:
fruit = 'Invalid number. Please enter a number between 1 and 5.';
}
result.textContent = fruit;
});
});