-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
57 lines (46 loc) · 1.73 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* Generate a function connected to the buttons. Once a button has being clicked together with the SUBMIT button,
it should show the rating in a new tab/in an alert window*/
/*
Once any button is clicked, the rating number should be stored in a variable.
1. Create 5 different variables which will take the input from each button (5);
2. Create 5 variables which will determine the value of each button (5);
*/
const button1Input = document.querySelector("#button1");
button1Input.addEventListener("click", getRating);
const button2Input = document.querySelector("#button2");
button2Input.addEventListener("click", getRating);
const button3Input = document.querySelector("#button3");
button3Input.addEventListener("click", getRating);
const button4Input = document.querySelector("#button4");
button4Input.addEventListener("click", getRating);
const button5Input = document.querySelector("#button5");
button5Input.addEventListener("click", getRating);
// let button = [1, 2, 3, 4, 5];
//let feedback
/*case 1:
selectedButton = button3Input;
console.log(button[0]);
break;*/
function getRating() {
switch(this) {
case button1Input:
console.log("1");
break;
case button2Input:
console.log("2");
break;
case button3Input:
console.log("3");
break;
case button4Input:
console.log("4");
break;
case button5Input:
console.log("5");
break;
default:
console.log("Thank you for visiting!");
}
alert(`You selected ${this.textcontent} out of 5. We appreciate you taking the time to give a rating!`);
}
document.querySelector("#submit").addEventListener("click", getRating);