SlideShare a Scribd company logo
1 of 13
having trouble with my code I'm using VScode to code a javascript code, please help
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>JavaScript Quiz</title>
<link rel="stylesheet" href="./script/.style.css" />
</head>
<body>
<header>
<h1>JavaScript Quiz</h1>
</header>
<main>
<section id="quiz">
<div id="question-container">
<h2 id="question"></h2>
<ul id="choices"></ul>
</div>
<div id="result-container">
<p id="result"></p>
</div>
<div id="submit-container">
<form id="submit-form">
<label for="initials">Enter your initials:</label>
<input type="text" id="initials" name="initials" required />
<button type="submit">Submit</button>
</form>
</div>
</section>
</main>
<script src="./script.js"></script>
</body>
</html>
//script.js
// Define the quiz settings
const quizSettings = {
duration: 75, // in seconds
penalty: 10, // in seconds
questions: [
{
text: "What does CSS stand for?",
choices: ["Computer Style Sheets", "Creative Style Sheets", "Cascading Style Sheets", "Colorful
Style Sheets"],
answer: "Cascading Style Sheets"
},
{
text: "What is the correct syntax for referring to an external script called 'script.js'?",
choices: ["<script src='script.js'>", "<script href='script.js'>", "<script name='script.js'>", "<script
file='script.js'>"],
answer: "<script src='script.js'>"
},
{
text: "Inside which HTML element do we put the JavaScript?",
choices: ["<script>", "<javascript>", "<scripting>", "<js>"],
answer: "<script>"
},
{
text: "What is the correct syntax for creating a new array in JavaScript?",
choices: ["var myArray = [];", "var myArray = {};", "var myArray = new array();", "var
myArray = array();"],
answer: "var myArray = [];"
},
{
text: "Which operator is used to assign a value to a variable?",
choices: ["=", "*", "+", "-"],
answer: "="
}
]
};
// Define variables for HTML elements
const startButton = document.getElementById("start-button");
const quizContainer = document.getElementById("quiz-container");
const questionText = document.getElementById("question-text");
const choicesContainer = document.getElementById("choices-container");
const feedbackText = document.getElementById("feedback-text");
const submitContainer = document.getElementById("submit-container");
const initialsInput = document.getElementById("initials-input");
const submitButton = document.getElementById("submit-button");
// Define variables for quiz state
let currentQuestionIndex;
let timeLeft;
let score;
// Add click event listener to start button
startButton.addEventListener("click", startQuiz);
// Define function to start the quiz
function startQuiz() {
currentQuestionIndex = 0;
timeLeft = quizSettings.duration;
score = 0;
// Hide start button and show quiz container
startButton.classList.add("hidden");
quizContainer.classList.remove("hidden");
// Start the timer
const timerInterval = setInterval(() => {
timeLeft--;
if (timeLeft <= 0) {
endQuiz();
clearInterval(timerInterval);
}
}, 1000);
// Display the first question
displayQuestion();
}
// Define function to display a question
function displayQuestion() {
// Get the current question from the quiz settings
const currentQuestion = quizSettings.questions[currentQuestionIndex];
// Update the question text and answer choices in the HTML
questionText.textContent = currentQuestion.text;
choicesContainer.innerHTML = "";
currentQuestion.choices.forEach(choice => {
const choiceButton = document.createElement("button");
choiceButton.textContent = choice;
choiceButton.addEventListener("click", () => {
checkAnswer(choice, currentQuestion.answer);
});
choicesContainer.appendChild(choiceButton);
});
}
// Define function to check the user's answer
function checkAnswer(answer) {
if (answer === quizData[currentQuestionIndex].correctAnswer) {
// Answer is correct
userScore += 10;
feedbackEl.textContent = "Correct!";
} else {
// Answer is incorrect
timeLeft -= 10;
feedbackEl.textContent = "Wrong!";
}
// Move on to the next question or end the quiz
currentQuestionIndex++;
if (currentQuestionIndex === quizData.length) {
endQuiz();
} else {
displayQuestion();
}
}
// Define function to end the quiz
function endQuiz() {
// Stop the timer
clearInterval(timerInterval);
// Show the final score and hide the quiz content
quizEl.classList.add("hidden");
scoreEl.textContent = userScore;
scoreContainerEl.classList.remove("hidden");
}
// Define event listener for when the user submits their score
submitBtn.addEventListener("click", function (event) {
event.preventDefault();
// Get the user's initials and score
var initials = initialsInputEl.value.trim();
if (initials !== "") {
var highScores = JSON.parse(localStorage.getItem("highScores")) || [];
highScores.push({
initials: initials,
score: userScore,
});
localStorage.setItem("highScores", JSON.stringify(highScores));
// Redirect to high scores page
window.location.href = "highscores.html";
}
});
// Start the quiz when the user clicks the start button
startBtn.addEventListener("click", startQuiz);
// Define function to check the user's answer
function checkAnswer(userAnswer, correctAnswer) {
if (userAnswer === correctAnswer) {
feedbackText.textContent = "Correct!";
score++;
} else {
}
feedbackText.textContent = "Wrong!";
timeLeft -= quizSettings.penalty;
if (timeLeft < 0) {
}
timeLeft = 0;
}
//style.css
/* Global Styles */
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: 16px;
line-height: 1.5;
color: #333;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
h1, h2, h3, h4, h5, h6 {
margin-bottom: 10px;
}
button {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: 16px;
line-height: 1.5;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
padding: 10px 20px;
cursor: pointer;
}
button:hover {
background-color: #0069d9;
}
/* Quiz Styles */
.quiz {
margin-bottom: 40px;
}
.quiz-question {
margin-bottom: 20px;
}
.quiz-choices {
list-style: none;
padding-left: 0;
}
.quiz-choices li {
margin-bottom: 10px;
}
.quiz-choices input[type="radio"] {
display: none;
}
.quiz-choices label {
display: block;
position: relative;
padding-left: 30px;
cursor: pointer;
}
.quiz-choices label::before {
content: '';
display: block;
position: absolute;
top: 0;
left: 0;
width: 20px;
height: 20px;
border: 1px solid #aaa;
border-radius: 50%;
}
.quiz-choices input[type="radio"]:checked + label::before {
background-color: #007bff;
border-color: #007bff;
}
.quiz-timer {
margin-bottom: 20px;
}
.quiz-score {
margin-bottom: 20px;
}
.quiz-form {
display: none;
}
.quiz-form label {
display: block;
margin-bottom: 10px;
}
.quiz-form input[type="text"] {
width: 100%;
padding: 5px;
border: 1px solid #aaa;
border-radius: 5px;
margin-bottom: 20px;
}
.quiz-form button[type="submit"] {
display: block;
margin: 0 auto;
}
having trouble with my code I'm using VScode to code a javascript code.docx

More Related Content

Similar to having trouble with my code I'm using VScode to code a javascript code.docx

МИХАЙЛО БОДНАРЧУК «SuperCharged End to End Testing with CodeceptJS» QADay 2019
МИХАЙЛО БОДНАРЧУК «SuperCharged End to End Testing with CodeceptJS»  QADay 2019МИХАЙЛО БОДНАРЧУК «SuperCharged End to End Testing with CodeceptJS»  QADay 2019
МИХАЙЛО БОДНАРЧУК «SuperCharged End to End Testing with CodeceptJS» QADay 2019GoQA
 
Join the darkside: Selenium testing with Nightwatch.js
Join the darkside: Selenium testing with Nightwatch.jsJoin the darkside: Selenium testing with Nightwatch.js
Join the darkside: Selenium testing with Nightwatch.jsSeth McLaughlin
 
React Native: JS MVC Meetup #15
React Native: JS MVC Meetup #15React Native: JS MVC Meetup #15
React Native: JS MVC Meetup #15Rob Gietema
 
MeetJS Summit 2016: React.js enlightenment
MeetJS Summit 2016: React.js enlightenmentMeetJS Summit 2016: React.js enlightenment
MeetJS Summit 2016: React.js enlightenmentArtur Szott
 
Academy PRO: React native - building first scenes
Academy PRO: React native - building first scenesAcademy PRO: React native - building first scenes
Academy PRO: React native - building first scenesBinary Studio
 
JavaScript Testing for Rubyists
JavaScript Testing for RubyistsJavaScript Testing for Rubyists
JavaScript Testing for RubyistsJamie Dyer
 
Creating a Facebook Clone - Part XXVIII.pdf
Creating a Facebook Clone - Part XXVIII.pdfCreating a Facebook Clone - Part XXVIII.pdf
Creating a Facebook Clone - Part XXVIII.pdfShaiAlmog1
 
Android Event and IntentAndroid Event and Intent
Android Event and IntentAndroid Event and IntentAndroid Event and IntentAndroid Event and Intent
Android Event and IntentAndroid Event and Intentadmin220812
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoRob Bontekoe
 
Violet Peña - Storybook: A React Tool For Your Whole Team
Violet Peña - Storybook: A React Tool For Your Whole TeamViolet Peña - Storybook: A React Tool For Your Whole Team
Violet Peña - Storybook: A React Tool For Your Whole TeamAnton Caceres
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ EtsyNishan Subedi
 
Mashing up JavaScript – Advanced Techniques for modern Web Apps
Mashing up JavaScript – Advanced Techniques for modern Web AppsMashing up JavaScript – Advanced Techniques for modern Web Apps
Mashing up JavaScript – Advanced Techniques for modern Web AppsBastian Hofmann
 
Version1.0 StartHTML000000279 EndHTML000043225 StartFragment0000.docx
Version1.0 StartHTML000000279 EndHTML000043225 StartFragment0000.docxVersion1.0 StartHTML000000279 EndHTML000043225 StartFragment0000.docx
Version1.0 StartHTML000000279 EndHTML000043225 StartFragment0000.docxtienboileau
 
HTML5 & The Open Web - at Nackademin
HTML5 & The Open Web -  at NackademinHTML5 & The Open Web -  at Nackademin
HTML5 & The Open Web - at NackademinRobert Nyman
 

Similar to having trouble with my code I'm using VScode to code a javascript code.docx (20)

Java script cookies
Java script   cookiesJava script   cookies
Java script cookies
 
МИХАЙЛО БОДНАРЧУК «SuperCharged End to End Testing with CodeceptJS» QADay 2019
МИХАЙЛО БОДНАРЧУК «SuperCharged End to End Testing with CodeceptJS»  QADay 2019МИХАЙЛО БОДНАРЧУК «SuperCharged End to End Testing with CodeceptJS»  QADay 2019
МИХАЙЛО БОДНАРЧУК «SuperCharged End to End Testing with CodeceptJS» QADay 2019
 
Clean Javascript
Clean JavascriptClean Javascript
Clean Javascript
 
Join the darkside: Selenium testing with Nightwatch.js
Join the darkside: Selenium testing with Nightwatch.jsJoin the darkside: Selenium testing with Nightwatch.js
Join the darkside: Selenium testing with Nightwatch.js
 
React Native: JS MVC Meetup #15
React Native: JS MVC Meetup #15React Native: JS MVC Meetup #15
React Native: JS MVC Meetup #15
 
Events - Part 2
Events - Part 2Events - Part 2
Events - Part 2
 
MeetJS Summit 2016: React.js enlightenment
MeetJS Summit 2016: React.js enlightenmentMeetJS Summit 2016: React.js enlightenment
MeetJS Summit 2016: React.js enlightenment
 
Academy PRO: React native - building first scenes
Academy PRO: React native - building first scenesAcademy PRO: React native - building first scenes
Academy PRO: React native - building first scenes
 
JavaScript Testing for Rubyists
JavaScript Testing for RubyistsJavaScript Testing for Rubyists
JavaScript Testing for Rubyists
 
Backbone - TDC 2011 Floripa
Backbone - TDC 2011 FloripaBackbone - TDC 2011 Floripa
Backbone - TDC 2011 Floripa
 
Creating a Facebook Clone - Part XXVIII.pdf
Creating a Facebook Clone - Part XXVIII.pdfCreating a Facebook Clone - Part XXVIII.pdf
Creating a Facebook Clone - Part XXVIII.pdf
 
Day 5
Day 5Day 5
Day 5
 
Android Event and IntentAndroid Event and Intent
Android Event and IntentAndroid Event and IntentAndroid Event and IntentAndroid Event and Intent
Android Event and IntentAndroid Event and Intent
 
Mashing up JavaScript
Mashing up JavaScriptMashing up JavaScript
Mashing up JavaScript
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" Domino
 
Violet Peña - Storybook: A React Tool For Your Whole Team
Violet Peña - Storybook: A React Tool For Your Whole TeamViolet Peña - Storybook: A React Tool For Your Whole Team
Violet Peña - Storybook: A React Tool For Your Whole Team
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
Mashing up JavaScript – Advanced Techniques for modern Web Apps
Mashing up JavaScript – Advanced Techniques for modern Web AppsMashing up JavaScript – Advanced Techniques for modern Web Apps
Mashing up JavaScript – Advanced Techniques for modern Web Apps
 
Version1.0 StartHTML000000279 EndHTML000043225 StartFragment0000.docx
Version1.0 StartHTML000000279 EndHTML000043225 StartFragment0000.docxVersion1.0 StartHTML000000279 EndHTML000043225 StartFragment0000.docx
Version1.0 StartHTML000000279 EndHTML000043225 StartFragment0000.docx
 
HTML5 & The Open Web - at Nackademin
HTML5 & The Open Web -  at NackademinHTML5 & The Open Web -  at Nackademin
HTML5 & The Open Web - at Nackademin
 

More from Isaac9LjWelchq

help 4- A ray of light is sent in a random direction towards the x-axi.docx
help 4- A ray of light is sent in a random direction towards the x-axi.docxhelp 4- A ray of light is sent in a random direction towards the x-axi.docx
help 4- A ray of light is sent in a random direction towards the x-axi.docxIsaac9LjWelchq
 
hello- please dont just copy from other answers- the following is the.docx
hello- please dont just copy from other answers- the following is the.docxhello- please dont just copy from other answers- the following is the.docx
hello- please dont just copy from other answers- the following is the.docxIsaac9LjWelchq
 
Hello- I am working on writing a penetration test plan for a fictitiou.docx
Hello- I am working on writing a penetration test plan for a fictitiou.docxHello- I am working on writing a penetration test plan for a fictitiou.docx
Hello- I am working on writing a penetration test plan for a fictitiou.docxIsaac9LjWelchq
 
Hello- I am struggling with figuring out how to solve for this The hor.docx
Hello- I am struggling with figuring out how to solve for this The hor.docxHello- I am struggling with figuring out how to solve for this The hor.docx
Hello- I am struggling with figuring out how to solve for this The hor.docxIsaac9LjWelchq
 
Hello! I need help with below project-Thank You- Please name and expla.docx
Hello! I need help with below project-Thank You- Please name and expla.docxHello! I need help with below project-Thank You- Please name and expla.docx
Hello! I need help with below project-Thank You- Please name and expla.docxIsaac9LjWelchq
 
Hello I wanted to know if I can get help with my medical information c.docx
Hello I wanted to know if I can get help with my medical information c.docxHello I wanted to know if I can get help with my medical information c.docx
Hello I wanted to know if I can get help with my medical information c.docxIsaac9LjWelchq
 
Hector loved visiting and playing with his grandson- David- Today was.docx
Hector loved visiting and playing with his grandson- David- Today was.docxHector loved visiting and playing with his grandson- David- Today was.docx
Hector loved visiting and playing with his grandson- David- Today was.docxIsaac9LjWelchq
 
Health psychology is a(n) - based science because practitioners are tr.docx
Health psychology is a(n) - based science because practitioners are tr.docxHealth psychology is a(n) - based science because practitioners are tr.docx
Health psychology is a(n) - based science because practitioners are tr.docxIsaac9LjWelchq
 
Healthcare Operations Analysis Utilizing Information Technology Explai.docx
Healthcare Operations Analysis Utilizing Information Technology Explai.docxHealthcare Operations Analysis Utilizing Information Technology Explai.docx
Healthcare Operations Analysis Utilizing Information Technology Explai.docxIsaac9LjWelchq
 
Hearing 10- What is the function of each of the following anatomical f.docx
Hearing 10- What is the function of each of the following anatomical f.docxHearing 10- What is the function of each of the following anatomical f.docx
Hearing 10- What is the function of each of the following anatomical f.docxIsaac9LjWelchq
 
Health information is important to public health authorities during an.docx
Health information is important to public health authorities during an.docxHealth information is important to public health authorities during an.docx
Health information is important to public health authorities during an.docxIsaac9LjWelchq
 
he reflex and reaction lab helped us understand how different factors.docx
he reflex and reaction lab helped us understand how different factors.docxhe reflex and reaction lab helped us understand how different factors.docx
he reflex and reaction lab helped us understand how different factors.docxIsaac9LjWelchq
 
How they can live a more Eco-friendly- Sustainable and Community Engag.docx
How they can live a more Eco-friendly- Sustainable and Community Engag.docxHow they can live a more Eco-friendly- Sustainable and Community Engag.docx
How they can live a more Eco-friendly- Sustainable and Community Engag.docxIsaac9LjWelchq
 
How to determine whether a language is regular or not using Myhill-Ner.docx
How to determine whether a language is regular or not using Myhill-Ner.docxHow to determine whether a language is regular or not using Myhill-Ner.docx
How to determine whether a language is regular or not using Myhill-Ner.docxIsaac9LjWelchq
 
How many references are there to the list that refers to after the fol.docx
How many references are there to the list that refers to after the fol.docxHow many references are there to the list that refers to after the fol.docx
How many references are there to the list that refers to after the fol.docxIsaac9LjWelchq
 
How is the protective group removed to allow the addition of nucleotid.docx
How is the protective group removed to allow the addition of nucleotid.docxHow is the protective group removed to allow the addition of nucleotid.docx
How is the protective group removed to allow the addition of nucleotid.docxIsaac9LjWelchq
 
Has it been shown in the lab that simple organic compounds have formed.docx
Has it been shown in the lab that simple organic compounds have formed.docxHas it been shown in the lab that simple organic compounds have formed.docx
Has it been shown in the lab that simple organic compounds have formed.docxIsaac9LjWelchq
 
How many possible ways can you roll a seven- What is the probability o.docx
How many possible ways can you roll a seven- What is the probability o.docxHow many possible ways can you roll a seven- What is the probability o.docx
How many possible ways can you roll a seven- What is the probability o.docxIsaac9LjWelchq
 
have type O blood- (Round your answers to four decimal places-).docx
have type O blood- (Round your answers to four decimal places-).docxhave type O blood- (Round your answers to four decimal places-).docx
have type O blood- (Round your answers to four decimal places-).docxIsaac9LjWelchq
 
How many ways can Marie choose 2 pizza toppings from a menu of 8 toppi.docx
How many ways can Marie choose 2 pizza toppings from a menu of 8 toppi.docxHow many ways can Marie choose 2 pizza toppings from a menu of 8 toppi.docx
How many ways can Marie choose 2 pizza toppings from a menu of 8 toppi.docxIsaac9LjWelchq
 

More from Isaac9LjWelchq (20)

help 4- A ray of light is sent in a random direction towards the x-axi.docx
help 4- A ray of light is sent in a random direction towards the x-axi.docxhelp 4- A ray of light is sent in a random direction towards the x-axi.docx
help 4- A ray of light is sent in a random direction towards the x-axi.docx
 
hello- please dont just copy from other answers- the following is the.docx
hello- please dont just copy from other answers- the following is the.docxhello- please dont just copy from other answers- the following is the.docx
hello- please dont just copy from other answers- the following is the.docx
 
Hello- I am working on writing a penetration test plan for a fictitiou.docx
Hello- I am working on writing a penetration test plan for a fictitiou.docxHello- I am working on writing a penetration test plan for a fictitiou.docx
Hello- I am working on writing a penetration test plan for a fictitiou.docx
 
Hello- I am struggling with figuring out how to solve for this The hor.docx
Hello- I am struggling with figuring out how to solve for this The hor.docxHello- I am struggling with figuring out how to solve for this The hor.docx
Hello- I am struggling with figuring out how to solve for this The hor.docx
 
Hello! I need help with below project-Thank You- Please name and expla.docx
Hello! I need help with below project-Thank You- Please name and expla.docxHello! I need help with below project-Thank You- Please name and expla.docx
Hello! I need help with below project-Thank You- Please name and expla.docx
 
Hello I wanted to know if I can get help with my medical information c.docx
Hello I wanted to know if I can get help with my medical information c.docxHello I wanted to know if I can get help with my medical information c.docx
Hello I wanted to know if I can get help with my medical information c.docx
 
Hector loved visiting and playing with his grandson- David- Today was.docx
Hector loved visiting and playing with his grandson- David- Today was.docxHector loved visiting and playing with his grandson- David- Today was.docx
Hector loved visiting and playing with his grandson- David- Today was.docx
 
Health psychology is a(n) - based science because practitioners are tr.docx
Health psychology is a(n) - based science because practitioners are tr.docxHealth psychology is a(n) - based science because practitioners are tr.docx
Health psychology is a(n) - based science because practitioners are tr.docx
 
Healthcare Operations Analysis Utilizing Information Technology Explai.docx
Healthcare Operations Analysis Utilizing Information Technology Explai.docxHealthcare Operations Analysis Utilizing Information Technology Explai.docx
Healthcare Operations Analysis Utilizing Information Technology Explai.docx
 
Hearing 10- What is the function of each of the following anatomical f.docx
Hearing 10- What is the function of each of the following anatomical f.docxHearing 10- What is the function of each of the following anatomical f.docx
Hearing 10- What is the function of each of the following anatomical f.docx
 
Health information is important to public health authorities during an.docx
Health information is important to public health authorities during an.docxHealth information is important to public health authorities during an.docx
Health information is important to public health authorities during an.docx
 
he reflex and reaction lab helped us understand how different factors.docx
he reflex and reaction lab helped us understand how different factors.docxhe reflex and reaction lab helped us understand how different factors.docx
he reflex and reaction lab helped us understand how different factors.docx
 
How they can live a more Eco-friendly- Sustainable and Community Engag.docx
How they can live a more Eco-friendly- Sustainable and Community Engag.docxHow they can live a more Eco-friendly- Sustainable and Community Engag.docx
How they can live a more Eco-friendly- Sustainable and Community Engag.docx
 
How to determine whether a language is regular or not using Myhill-Ner.docx
How to determine whether a language is regular or not using Myhill-Ner.docxHow to determine whether a language is regular or not using Myhill-Ner.docx
How to determine whether a language is regular or not using Myhill-Ner.docx
 
How many references are there to the list that refers to after the fol.docx
How many references are there to the list that refers to after the fol.docxHow many references are there to the list that refers to after the fol.docx
How many references are there to the list that refers to after the fol.docx
 
How is the protective group removed to allow the addition of nucleotid.docx
How is the protective group removed to allow the addition of nucleotid.docxHow is the protective group removed to allow the addition of nucleotid.docx
How is the protective group removed to allow the addition of nucleotid.docx
 
Has it been shown in the lab that simple organic compounds have formed.docx
Has it been shown in the lab that simple organic compounds have formed.docxHas it been shown in the lab that simple organic compounds have formed.docx
Has it been shown in the lab that simple organic compounds have formed.docx
 
How many possible ways can you roll a seven- What is the probability o.docx
How many possible ways can you roll a seven- What is the probability o.docxHow many possible ways can you roll a seven- What is the probability o.docx
How many possible ways can you roll a seven- What is the probability o.docx
 
have type O blood- (Round your answers to four decimal places-).docx
have type O blood- (Round your answers to four decimal places-).docxhave type O blood- (Round your answers to four decimal places-).docx
have type O blood- (Round your answers to four decimal places-).docx
 
How many ways can Marie choose 2 pizza toppings from a menu of 8 toppi.docx
How many ways can Marie choose 2 pizza toppings from a menu of 8 toppi.docxHow many ways can Marie choose 2 pizza toppings from a menu of 8 toppi.docx
How many ways can Marie choose 2 pizza toppings from a menu of 8 toppi.docx
 

Recently uploaded

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 

Recently uploaded (20)

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 

having trouble with my code I'm using VScode to code a javascript code.docx

  • 1. having trouble with my code I'm using VScode to code a javascript code, please help <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>JavaScript Quiz</title> <link rel="stylesheet" href="./script/.style.css" /> </head> <body> <header> <h1>JavaScript Quiz</h1> </header> <main> <section id="quiz"> <div id="question-container"> <h2 id="question"></h2> <ul id="choices"></ul> </div> <div id="result-container"> <p id="result"></p> </div>
  • 2. <div id="submit-container"> <form id="submit-form"> <label for="initials">Enter your initials:</label> <input type="text" id="initials" name="initials" required /> <button type="submit">Submit</button> </form> </div> </section> </main> <script src="./script.js"></script> </body> </html> //script.js // Define the quiz settings const quizSettings = { duration: 75, // in seconds penalty: 10, // in seconds questions: [ { text: "What does CSS stand for?", choices: ["Computer Style Sheets", "Creative Style Sheets", "Cascading Style Sheets", "Colorful Style Sheets"], answer: "Cascading Style Sheets" },
  • 3. { text: "What is the correct syntax for referring to an external script called 'script.js'?", choices: ["<script src='script.js'>", "<script href='script.js'>", "<script name='script.js'>", "<script file='script.js'>"], answer: "<script src='script.js'>" }, { text: "Inside which HTML element do we put the JavaScript?", choices: ["<script>", "<javascript>", "<scripting>", "<js>"], answer: "<script>" }, { text: "What is the correct syntax for creating a new array in JavaScript?", choices: ["var myArray = [];", "var myArray = {};", "var myArray = new array();", "var myArray = array();"], answer: "var myArray = [];" }, { text: "Which operator is used to assign a value to a variable?", choices: ["=", "*", "+", "-"], answer: "=" } ] };
  • 4. // Define variables for HTML elements const startButton = document.getElementById("start-button"); const quizContainer = document.getElementById("quiz-container"); const questionText = document.getElementById("question-text"); const choicesContainer = document.getElementById("choices-container"); const feedbackText = document.getElementById("feedback-text"); const submitContainer = document.getElementById("submit-container"); const initialsInput = document.getElementById("initials-input"); const submitButton = document.getElementById("submit-button"); // Define variables for quiz state let currentQuestionIndex; let timeLeft; let score; // Add click event listener to start button startButton.addEventListener("click", startQuiz); // Define function to start the quiz function startQuiz() { currentQuestionIndex = 0; timeLeft = quizSettings.duration; score = 0; // Hide start button and show quiz container startButton.classList.add("hidden"); quizContainer.classList.remove("hidden");
  • 5. // Start the timer const timerInterval = setInterval(() => { timeLeft--; if (timeLeft <= 0) { endQuiz(); clearInterval(timerInterval); } }, 1000); // Display the first question displayQuestion(); } // Define function to display a question function displayQuestion() { // Get the current question from the quiz settings const currentQuestion = quizSettings.questions[currentQuestionIndex]; // Update the question text and answer choices in the HTML questionText.textContent = currentQuestion.text; choicesContainer.innerHTML = ""; currentQuestion.choices.forEach(choice => { const choiceButton = document.createElement("button"); choiceButton.textContent = choice; choiceButton.addEventListener("click", () => { checkAnswer(choice, currentQuestion.answer);
  • 6. }); choicesContainer.appendChild(choiceButton); }); } // Define function to check the user's answer function checkAnswer(answer) { if (answer === quizData[currentQuestionIndex].correctAnswer) { // Answer is correct userScore += 10; feedbackEl.textContent = "Correct!"; } else { // Answer is incorrect timeLeft -= 10; feedbackEl.textContent = "Wrong!"; } // Move on to the next question or end the quiz currentQuestionIndex++; if (currentQuestionIndex === quizData.length) { endQuiz(); } else { displayQuestion(); } }
  • 7. // Define function to end the quiz function endQuiz() { // Stop the timer clearInterval(timerInterval); // Show the final score and hide the quiz content quizEl.classList.add("hidden"); scoreEl.textContent = userScore; scoreContainerEl.classList.remove("hidden"); } // Define event listener for when the user submits their score submitBtn.addEventListener("click", function (event) { event.preventDefault(); // Get the user's initials and score var initials = initialsInputEl.value.trim(); if (initials !== "") { var highScores = JSON.parse(localStorage.getItem("highScores")) || []; highScores.push({ initials: initials, score: userScore, }); localStorage.setItem("highScores", JSON.stringify(highScores)); // Redirect to high scores page window.location.href = "highscores.html";
  • 8. } }); // Start the quiz when the user clicks the start button startBtn.addEventListener("click", startQuiz); // Define function to check the user's answer function checkAnswer(userAnswer, correctAnswer) { if (userAnswer === correctAnswer) { feedbackText.textContent = "Correct!"; score++; } else { } feedbackText.textContent = "Wrong!"; timeLeft -= quizSettings.penalty; if (timeLeft < 0) { } timeLeft = 0; } //style.css /* Global Styles */ * { box-sizing: border-box; margin: 0; padding: 0;
  • 9. } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-size: 16px; line-height: 1.5; color: #333; } .container { max-width: 800px; margin: 0 auto; padding: 20px; } h1, h2, h3, h4, h5, h6 { margin-bottom: 10px; } button { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-size: 16px; line-height: 1.5; background-color: #007bff; color: #fff; border: none; border-radius: 5px;
  • 10. padding: 10px 20px; cursor: pointer; } button:hover { background-color: #0069d9; } /* Quiz Styles */ .quiz { margin-bottom: 40px; } .quiz-question { margin-bottom: 20px; } .quiz-choices { list-style: none; padding-left: 0; } .quiz-choices li { margin-bottom: 10px; } .quiz-choices input[type="radio"] { display: none; }
  • 11. .quiz-choices label { display: block; position: relative; padding-left: 30px; cursor: pointer; } .quiz-choices label::before { content: ''; display: block; position: absolute; top: 0; left: 0; width: 20px; height: 20px; border: 1px solid #aaa; border-radius: 50%; } .quiz-choices input[type="radio"]:checked + label::before { background-color: #007bff; border-color: #007bff; } .quiz-timer { margin-bottom: 20px;
  • 12. } .quiz-score { margin-bottom: 20px; } .quiz-form { display: none; } .quiz-form label { display: block; margin-bottom: 10px; } .quiz-form input[type="text"] { width: 100%; padding: 5px; border: 1px solid #aaa; border-radius: 5px; margin-bottom: 20px; } .quiz-form button[type="submit"] { display: block; margin: 0 auto; }