Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quiz website #4

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions ananya_20233049/cquiz.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quiz</title>
<link rel="stylesheet" href="style.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">

</head>
<body>
<div class="app">
<h1>Quiz!</h1>
<div class="quiz">
<h2 id="question">Your Question is:</h2>
<div id="answer-buttons">
<button class="btn">Answer 1</button>
<button class="btn">Answer 2</button>
<button class="btn">Answer 3</button>
<button class="btn">Answer 4</button>
</div>
<button id="back" onclick="Gotohome()">Home</button>
<button id="next-btn">Next</button>

</div>

</div4>

<script src="script.js"></script>
</body>
</html>
32 changes: 32 additions & 0 deletions ananya_20233049/dsa.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quiz</title>
<link rel="stylesheet" href="style.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">

</head>
<body>
<div class="app">
<h1>Quiz!</h1>
<div class="quiz">
<h2 id="question">Your Question is:</h2>
<div id="answer-buttons">
<button class="btn">Answer 1</button>
<button class="btn">Answer 2</button>
<button class="btn">Answer 3</button>
<button class="btn">Answer 4</button>
</div>
<button id="back" onclick="Gotohome()">Home</button>
<button id="next-btn">Next</button>
</div>

</div4>

<script src="dsasc.js"></script>
</body>
</html>
136 changes: 136 additions & 0 deletions ananya_20233049/dsasc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
const questions=[
{
question:"What is a data structure?",
answers:[
{text:'A programming language',correct:false},
{text:'A collection of algorithms',correct:false},
{text:'A way to store and organize data',correct:true},
{text:'A type of computer hardware',correct:false},
]
},
{
question:" Which data structure is used for implementing recursion?",
answers:[
{text:'queue',correct:false},
{text:'stack',correct:true},
{text:'vector',correct:false},
{text:'array',correct:false},
]
},
{
question:"The data structure required to check whether an expression contains a balanced parenthesis is?",
answers:[
{text:'stack',correct:true},
{text:'queue',correct:false},
{text:'tree',correct:false},
{text:'array',correct:false},
]
},
{
question:"What is the value of the postfix expression 6 3 2 4 + – *?",
answers:[
{text:'74',correct:false},
{text:'-18',correct:true},
{text:'-22',correct:false},
{text:'40',correct:false},
]
},
{
question:"The data structure required for Breadth First Traversal on a graph is?",
answers:[
{text:'Tree',correct:false},
{text:'Stack',correct:false},
{text:'Queue',correct:true},
{text:'Array',correct:false},
]
},
{
question:"Which of the following is not the type of queue?",
answers:[
{text:'priority queue',correct:false},
{text:'circular queue',correct:false},
{text:'single ended queue',correct:true},
{text:'ordinary queue',correct:false},
]
},
];


const questionElement=document.getElementById("question");
const answerButton=document.getElementById("answer-buttons");
const nextButton=document.getElementById("next-btn");
let curruentQuestionIndex=0;
let score=0;
function Gotohome(){
window.location="index.html";
}
function startQuiz(){
curruentQuestionIndex=0;
score=0;
nextButton.innerHTML="Next";
showQuestion();
}

function showQuestion(){
resetState();
let currentques=questions[curruentQuestionIndex];
let questionno=curruentQuestionIndex+1;
questionElement.innerHTML=questionno +'.'+currentques.question;
currentques.answers.forEach(answer=>{
const button=document.createElement("button");
button.innerHTML=answer.text;
button.classList.add("btn");
answerButton.appendChild(button);
if(answer.correct){
button.dataset.correct=answer.correct;
}
button.addEventListener("click",selectAnswer);
});
}
function resetState(){
nextButton.style.display="none";
while(answerButton.firstChild){
answerButton.removeChild(answerButton.firstChild);
}
}
function selectAnswer(e){
const selectedBtn=e.target;
const isCorrect=selectedBtn.dataset.correct==="true";
if(isCorrect){
selectedBtn.classList.add("correct");
score++;
}
else{
selectedBtn.classList.add("incorrect");
}
Array.from(answerButton.children).forEach(button=>{
if(button.dataset.correct==="true"){
button.classList.add("correct");
}
button.disabled=true;
});
nextButton.style.display="inline";
}
function showScore(){
resetState();
questionElement.innerHTML=`You scored ${score} out of ${questions.length}!`;
nextButton.innerHTML="Play Again";
nextButton.style.display="inline";
}
function handleNextButton(){
curruentQuestionIndex++;
if(curruentQuestionIndex<questions.length){
showQuestion();
}
else{
showScore();
}
}
nextButton.addEventListener("click",()=>{
if(curruentQuestionIndex<questions.length){
handleNextButton();
} else{
startQuiz();
}
});
startQuiz();
32 changes: 32 additions & 0 deletions ananya_20233049/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quizzer</title>
<link rel="stylesheet" href="style.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">

</head>
<body>
<div class="index">
<h1>Welcome to the Quiz!</h1>
<div class="topic">
<div id="answer-buttons">
<a href="cquiz.html">
<button class="button" >C programming quiz</button></a>
<a href="python.html">
<button class="button">Python Quiz</button></a>
<a href="dsa.html">
<button class="button">DSA quiz</button>
</a>
</div>
<button id="next-btn">Next</button>
</div>

</div4>

</body>
</html>
32 changes: 32 additions & 0 deletions ananya_20233049/python.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quiz</title>
<link rel="stylesheet" href="style.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">

</head>
<body>
<div class="app">
<h1>Quiz!</h1>
<div class="quiz">
<h2 id="question">Your Question is:</h2>
<div id="answer-buttons">
<button class="btn">Answer 1</button>
<button class="btn">Answer 2</button>
<button class="btn">Answer 3</button>
<button class="btn">Answer 4</button>
</div>
<button id="back" onclick="Gotohome()">Home</button>
<button id="next-btn">Next</button>
</div>

</div4>

<script src="pythonsc.js"></script>
</body>
</html>
Loading