-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
69 lines (65 loc) · 1.51 KB
/
test.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
58
59
60
61
62
63
64
65
66
67
68
69
const quiz = [
{
question: "What is the Collatz Conjecture?",
answers: [
{
text: "A conjecture that has not been proven or disproven",
correct: true,
},
{
text: "A mathematical formula for calculating prime numbers",
correct: false,
},
{
text: "A theorem about the distribution of prime numbers",
correct: false,
},
],
},
{
question: "What is the last number in a Collatz sequence for any number?",
answers: [
{
text: "1",
correct: true,
},
{
text: "2",
correct: false,
},
{
text: "3",
correct: false,
},
],
},
{
question: "What is the first number in a sequence list for number 5?",
answers: [
{
text: "5",
correct: true,
},
{
text: "1",
correct: false,
},
{
text: "10",
correct: false,
},
],
},
];
const checkAnswer = (question, userAnswer) => {
const quizQuestion = quiz.find(q => q.question === question);
if(!quizQuestion) {
console.log('Invalid question');
return false
}
const isCorrect = quizQuestion.answers.some(answer => answer.text === userAnswer && answer.correct);
return isCorrect;
}
const question = "What is the Collatz Conjecture?";
const userAnswer = "A that has not been proven or disproven";
console.log(checkAnswer(question, userAnswer)); // Should log true if the answer is correct