-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject-1.js
45 lines (38 loc) · 1.31 KB
/
project-1.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
// Variables
let btn = document.querySelector("#new-quote");
let quote = document.querySelector(".quote");
let person = document.querySelector(".person");
const quotes = [
{
quote: '"The best way to find yourself is to lose yourself in the service of others."',
person: "Mahatma Gandhi",
},
{
quote: '"if you want to live a happy life, tie it to goal, not to people or things."',
person: "Albert Einstein",
},
{
quote: '"At his best, man is the noblest of all animals; separated from law and justice he is the worst."',
person: "Aristotle",
},
{
quote: "\"Your time is limited, so don't waste it living someone else's life.\"",
person: "Steve Jobs",
},
{
quote: '"It doesn\'t matter how slowly you go as long as you do not stop"',
person: "Confucius",
},
];
let previousRandom;
btn.addEventListener("click", function () {
let random = Math.floor(Math.random() * quotes.length);
// check if the new random number is the same as the previous one
while (random === previousRandom) {
random = Math.floor(Math.random() * quotes.length);
}
quote.innerText = quotes[random].quote;
person.innerText = quotes[random].person;
// update previousRandom variable
previousRandom = random;
});