SlideShare a Scribd company logo
JAVASCRIPT Quiz                               by Kishan Phadte




<HTML>

<HEAD>

<TITLE>Quiz Program</TITLE>

<SCRIPT LANGUAGE="JavaScript">

//Question object

function Question() {

this.question=Question.arguments[0]

var n=Question.arguments.length

this.answers = new Array(n-2)

for(var i=1; i<n-1; ++i)

    this.answers[i-1]=Question.arguments[i]

this.correctAnswer=Question.arguments[n-1]

}

function readCookie() {
currentQuestion=0

numberOfQuestions=0

correctAnswers=0

score="None"

cookie=document.cookie

currentQuestion=getNumberValue(cookie,"currentQuestion")

numberOfQuestions=getNumberValue(cookie,"numberOfQuestions")

correctAnswers=getNumberValue(cookie,"correctAnswers")

if(numberOfQuestions>0)

    score=Math.round(correctAnswers*100/numberOfQuestions)

}

function getNumberValue(s,n) {

s=removeBlanks(s)

var pairs=s.split(";")

for(var i=0;i<pairs.length;++i) {

    var pairSplit=pairs[i].split("=")

    if(pairSplit[0]==n) {

    if(pairSplit.length>1) return parseInt(pairSplit[1])

    else return 0

    }

}

return 0

}

function removeBlanks(s) {

var temp=""
for(var i=0;i<s.length;++i) {

    var c=s.charAt(i)

    if(c!=" ") temp += c

}

return temp

}

function askNextQuestion() {

document.writeln("<H4 ALIGN='LEFT'>"

    +qa[currentQuestion].question+"</H4>")

displayAnswers()

}

function displayAnswers() {

document.writeln('<FORM NAME="answerForm">')

for(var ii=0;ii<qa[currentQuestion].answers.length;++ii) {

    document.writeln('<H4 ALIGN="LEFT">')

    document.writeln('<INPUT TYPE="RADIO" NAME="answer"> ')

    document.writeln(qa[currentQuestion].answers[ii])

    if(ii+1==qa[currentQuestion].answers.length) {

    document.writeln('<BR><BR><INPUT TYPE="BUTTON"')

    document.writeln('NAME="continue" VALUE="Continue" ')

    document.writeln(' onClick="checkAnswers()">')

    }

    document.writeln('</H4>')

}

document.writeln('</FORM>')
}

function checkAnswers() {

var numAnswers=qa[currentQuestion].answers.length

var correctAnswer=qa[currentQuestion].correctAnswer

for(var jj=0;jj<numAnswers;++jj) {

    if(document.answerForm.elements[jj].checked) {

    if(jj==correctAnswer){

        correct()

        break

    }else{

        incorrect()

        break

    }

    }

    if(jj==numAnswers){

    incorrect()

    break

    }

}

}

function correct() {

++currentQuestion

++numberOfQuestions

++correctAnswers

updateCookie()
location.reload(true)

}

function incorrect() {

++numberOfQuestions

updateCookie()

alert("Incorrect!")

location.reload(true)

}

function updateCookie() {

document.cookie="currentQuestion="+currentQuestion

document.cookie="numberOfQuestions="+numberOfQuestions

document.cookie="correctAnswers="+correctAnswers

}

function endQuiz() {

document.cookie="currentQuestion=0"

document.cookie="numberOfQuestions=0"

document.cookie="correctAnswers=0"

document.writeln('<FORM NAME="finishedForm">')

document.write("<H4 ALIGN='CENTER'>")

document.write("Congratulations! You have finished this quiz.")

document.write('<BR><BR>')

document.write("<img src='so.jpg' width=200 height=200 align='center'")

document.write('<BR><BR><INPUT TYPE="BUTTON" ')

document.writeln('NAME="restart" VALUE="Restart" ')

document.writeln(' onClick="restartQuiz()">')
document.writeln("</H4>")

document.writeln('</FORM>')

}

function restartQuiz()

{

location.reload(true);

}

</SCRIPT>



<SCRIPT LANGUAGE="JavaScript">

pageHeading="Corrupt Governance Quiz"

//Questions

var qa = new Array()

qa[0] = new Question("1) Who is the lead actor in the Lokpal Bill ?",

"Anna Hazare",

"John Abraham",

"Hrithik Roshan",

"Akshay Kumar",

0)

qa[1] = new Question("2) Who out of these set INDIA'S WINGS ON FIRE ?",

"Dragon",

"Gabbar Singh",

"Sonia Gandhi",

"Fireman",

2)
qa[2] = new Question("3) After how many days did ANNA Hazare break his hunger strike?",

"365 days",

"13 days",

"12 years",

"1 day",

1)

qa[3] = new Question("4) Who said that he is ANNAs <i>HANUMAN</i>?",

"KApil Sibbal",

"Arvind Kejriwaal",

"Sanjay Khan",

"Sanjay Dutt",

1)

qa[4] = new Question("5) Who is Father of our nation?",

"Laloo Prasad Yadav",

"Amar Singh",

"Sardar Manmohan Singh",

"M.K. Gandhi",

3)

qa[5] = new Question("6) Who believes in <I>CORRUPTION</I>?",

"Eminem",

"Bob Marley",

"Sonia Chor Gandhi",

"AKON",

2)

qa[6] = new Question("7) Anna Hazare is ",
"Labour (Gawandi)",

"Ex- Armyman",

"Gangster",

"Corrupt Minister",

1)

qa[7] = new Question("8) Who is SMS?",

"Salvatore Dali",

"Sardar Manmohan Singh",

"Rahul R. Gandhi",

"Narendra Modi",

1)

qa[8] = new Question("9) Who is Kiran Bedi?",

"IAS officer",

"Bus conductor",

"Animal activist",

"Scientist"

,0)

qa[9] = new Question("10) Who is <b>Arvind Kejriwal</b>?",

"Engineer from IIT Kharagpur",

"Surgeon",

"Astronomer",

"Fasting Specialist",

0)



</SCRIPT>
</HEAD>

<BODY>

<SCRIPT LANGUAGE="JavaScript"><!--

readCookie()

document.writeln("<H1 ALIGN='LEFT'>"+"<img src=corruption.jpg width=980 height=120/>"
+"<br>" +pageHeading+"</H1>"+"<hr>")

document.writeln("<P ALIGN='RIGHT'><B>Questions: "

+numberOfQuestions+"<BR>")

document.writeln("Correct Answers: "+correctAnswers+"<BR>")

document.writeln("Score: "+score+"</B>")



document.writeln("<img ALIGN='RIGHT' src='co.jpg' width=150 height=300/>")

if(currentQuestion >= qa.length) endQuiz()

else askNextQuestion()

// --></SCRIPT>

</BODY>

</HTML>
Result :

More Related Content

What's hot (20)

PDF
The Testing Games: Mocking, yay!
Donny Wals
 
PDF
The Ring programming language version 1.5.3 book - Part 44 of 184
Mahmoud Samir Fayed
 
PPTX
Lowering in C#: What really happens with your code?, from NDC Oslo 2019
David Wengier
 
PDF
The Ring programming language version 1.3 book - Part 34 of 88
Mahmoud Samir Fayed
 
PPTX
The secret unit testing tools no one has ever told you about
Dror Helper
 
PDF
The Ring programming language version 1.10 book - Part 54 of 212
Mahmoud Samir Fayed
 
KEY
Django quickstart
Marconi Moreto
 
PDF
The Ring programming language version 1.5.1 book - Part 51 of 180
Mahmoud Samir Fayed
 
PDF
Vaadin7
Joonas Lehtinen
 
PPTX
Михаил Матросов, Повседневный С++: boost и STL
Sergey Platonov
 
PPT
Indexing & query optimization
Jared Rosoff
 
PDF
Spock and Geb in Action
Christian Baranowski
 
PDF
The Ring programming language version 1.2 book - Part 32 of 84
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.3 book - Part 42 of 88
Mahmoud Samir Fayed
 
PDF
JSON and Swift, Still A Better Love Story Than Twilight
Donny Wals
 
PDF
The Ring programming language version 1.5.2 book - Part 41 of 181
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.9 book - Part 62 of 210
Mahmoud Samir Fayed
 
DOC
Baitap tkw
nguyenquy2101
 
PDF
MongoDB Oplog入門
Takahiro Inoue
 
PDF
Intro to OTP in Elixir
Jesse Anderson
 
The Testing Games: Mocking, yay!
Donny Wals
 
The Ring programming language version 1.5.3 book - Part 44 of 184
Mahmoud Samir Fayed
 
Lowering in C#: What really happens with your code?, from NDC Oslo 2019
David Wengier
 
The Ring programming language version 1.3 book - Part 34 of 88
Mahmoud Samir Fayed
 
The secret unit testing tools no one has ever told you about
Dror Helper
 
The Ring programming language version 1.10 book - Part 54 of 212
Mahmoud Samir Fayed
 
Django quickstart
Marconi Moreto
 
The Ring programming language version 1.5.1 book - Part 51 of 180
Mahmoud Samir Fayed
 
Михаил Матросов, Повседневный С++: boost и STL
Sergey Platonov
 
Indexing & query optimization
Jared Rosoff
 
Spock and Geb in Action
Christian Baranowski
 
The Ring programming language version 1.2 book - Part 32 of 84
Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 42 of 88
Mahmoud Samir Fayed
 
JSON and Swift, Still A Better Love Story Than Twilight
Donny Wals
 
The Ring programming language version 1.5.2 book - Part 41 of 181
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 62 of 210
Mahmoud Samir Fayed
 
Baitap tkw
nguyenquy2101
 
MongoDB Oplog入門
Takahiro Inoue
 
Intro to OTP in Elixir
Jesse Anderson
 

Viewers also liked (8)

PPT
Javascript quiz. Questions to ask when recruiting developers.
Alberto Naranjo
 
DOC
Javascript Question
Vinodkumar Saravana Chandrasekar
 
DOCX
Bit%20 ch02
Kodchawan Yookong
 
PPTX
Ecowhizz Prelims
Somnath Chanda
 
PPTX
XCentricity Quiz 2016 by Apratim Chandra Singh
Apratim Chandra Singh
 
PPTX
Prahelika prelims
Somnath Chanda
 
PPTX
Prahelika finals
Somnath Chanda
 
PPT
Quiz-Grand Finale
Somnath Chanda
 
Javascript quiz. Questions to ask when recruiting developers.
Alberto Naranjo
 
Bit%20 ch02
Kodchawan Yookong
 
Ecowhizz Prelims
Somnath Chanda
 
XCentricity Quiz 2016 by Apratim Chandra Singh
Apratim Chandra Singh
 
Prahelika prelims
Somnath Chanda
 
Prahelika finals
Somnath Chanda
 
Quiz-Grand Finale
Somnath Chanda
 
Ad

More from DM's College, Assagao Goa (9)

PPT
Chap12 project procurement management
DM's College, Assagao Goa
 
PPT
Chap09 project human resource management
DM's College, Assagao Goa
 
PPT
Chap08 project quality management
DM's College, Assagao Goa
 
PPT
Chap06 project time management
DM's College, Assagao Goa
 
PPT
Chap04 project integration management
DM's College, Assagao Goa
 
PPT
Chap01 introduction to project management
DM's College, Assagao Goa
 
PDF
Personal website
DM's College, Assagao Goa
 
PDF
Kishan Phadte's HTML Cross word
DM's College, Assagao Goa
 
PPTX
Android a glimpse by kishan phadte(BCA, Third Year undergraduate at DM's Col...
DM's College, Assagao Goa
 
Chap12 project procurement management
DM's College, Assagao Goa
 
Chap09 project human resource management
DM's College, Assagao Goa
 
Chap08 project quality management
DM's College, Assagao Goa
 
Chap06 project time management
DM's College, Assagao Goa
 
Chap04 project integration management
DM's College, Assagao Goa
 
Chap01 introduction to project management
DM's College, Assagao Goa
 
Personal website
DM's College, Assagao Goa
 
Kishan Phadte's HTML Cross word
DM's College, Assagao Goa
 
Android a glimpse by kishan phadte(BCA, Third Year undergraduate at DM's Col...
DM's College, Assagao Goa
 
Ad

Recently uploaded (20)

PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Python basic programing language for automation
DanialHabibi2
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 

Javascript quiz

  • 1. JAVASCRIPT Quiz by Kishan Phadte <HTML> <HEAD> <TITLE>Quiz Program</TITLE> <SCRIPT LANGUAGE="JavaScript"> //Question object function Question() { this.question=Question.arguments[0] var n=Question.arguments.length this.answers = new Array(n-2) for(var i=1; i<n-1; ++i) this.answers[i-1]=Question.arguments[i] this.correctAnswer=Question.arguments[n-1] } function readCookie() {
  • 2. currentQuestion=0 numberOfQuestions=0 correctAnswers=0 score="None" cookie=document.cookie currentQuestion=getNumberValue(cookie,"currentQuestion") numberOfQuestions=getNumberValue(cookie,"numberOfQuestions") correctAnswers=getNumberValue(cookie,"correctAnswers") if(numberOfQuestions>0) score=Math.round(correctAnswers*100/numberOfQuestions) } function getNumberValue(s,n) { s=removeBlanks(s) var pairs=s.split(";") for(var i=0;i<pairs.length;++i) { var pairSplit=pairs[i].split("=") if(pairSplit[0]==n) { if(pairSplit.length>1) return parseInt(pairSplit[1]) else return 0 } } return 0 } function removeBlanks(s) { var temp=""
  • 3. for(var i=0;i<s.length;++i) { var c=s.charAt(i) if(c!=" ") temp += c } return temp } function askNextQuestion() { document.writeln("<H4 ALIGN='LEFT'>" +qa[currentQuestion].question+"</H4>") displayAnswers() } function displayAnswers() { document.writeln('<FORM NAME="answerForm">') for(var ii=0;ii<qa[currentQuestion].answers.length;++ii) { document.writeln('<H4 ALIGN="LEFT">') document.writeln('<INPUT TYPE="RADIO" NAME="answer"> ') document.writeln(qa[currentQuestion].answers[ii]) if(ii+1==qa[currentQuestion].answers.length) { document.writeln('<BR><BR><INPUT TYPE="BUTTON"') document.writeln('NAME="continue" VALUE="Continue" ') document.writeln(' onClick="checkAnswers()">') } document.writeln('</H4>') } document.writeln('</FORM>')
  • 4. } function checkAnswers() { var numAnswers=qa[currentQuestion].answers.length var correctAnswer=qa[currentQuestion].correctAnswer for(var jj=0;jj<numAnswers;++jj) { if(document.answerForm.elements[jj].checked) { if(jj==correctAnswer){ correct() break }else{ incorrect() break } } if(jj==numAnswers){ incorrect() break } } } function correct() { ++currentQuestion ++numberOfQuestions ++correctAnswers updateCookie()
  • 5. location.reload(true) } function incorrect() { ++numberOfQuestions updateCookie() alert("Incorrect!") location.reload(true) } function updateCookie() { document.cookie="currentQuestion="+currentQuestion document.cookie="numberOfQuestions="+numberOfQuestions document.cookie="correctAnswers="+correctAnswers } function endQuiz() { document.cookie="currentQuestion=0" document.cookie="numberOfQuestions=0" document.cookie="correctAnswers=0" document.writeln('<FORM NAME="finishedForm">') document.write("<H4 ALIGN='CENTER'>") document.write("Congratulations! You have finished this quiz.") document.write('<BR><BR>') document.write("<img src='so.jpg' width=200 height=200 align='center'") document.write('<BR><BR><INPUT TYPE="BUTTON" ') document.writeln('NAME="restart" VALUE="Restart" ') document.writeln(' onClick="restartQuiz()">')
  • 6. document.writeln("</H4>") document.writeln('</FORM>') } function restartQuiz() { location.reload(true); } </SCRIPT> <SCRIPT LANGUAGE="JavaScript"> pageHeading="Corrupt Governance Quiz" //Questions var qa = new Array() qa[0] = new Question("1) Who is the lead actor in the Lokpal Bill ?", "Anna Hazare", "John Abraham", "Hrithik Roshan", "Akshay Kumar", 0) qa[1] = new Question("2) Who out of these set INDIA'S WINGS ON FIRE ?", "Dragon", "Gabbar Singh", "Sonia Gandhi", "Fireman", 2)
  • 7. qa[2] = new Question("3) After how many days did ANNA Hazare break his hunger strike?", "365 days", "13 days", "12 years", "1 day", 1) qa[3] = new Question("4) Who said that he is ANNAs <i>HANUMAN</i>?", "KApil Sibbal", "Arvind Kejriwaal", "Sanjay Khan", "Sanjay Dutt", 1) qa[4] = new Question("5) Who is Father of our nation?", "Laloo Prasad Yadav", "Amar Singh", "Sardar Manmohan Singh", "M.K. Gandhi", 3) qa[5] = new Question("6) Who believes in <I>CORRUPTION</I>?", "Eminem", "Bob Marley", "Sonia Chor Gandhi", "AKON", 2) qa[6] = new Question("7) Anna Hazare is ",
  • 8. "Labour (Gawandi)", "Ex- Armyman", "Gangster", "Corrupt Minister", 1) qa[7] = new Question("8) Who is SMS?", "Salvatore Dali", "Sardar Manmohan Singh", "Rahul R. Gandhi", "Narendra Modi", 1) qa[8] = new Question("9) Who is Kiran Bedi?", "IAS officer", "Bus conductor", "Animal activist", "Scientist" ,0) qa[9] = new Question("10) Who is <b>Arvind Kejriwal</b>?", "Engineer from IIT Kharagpur", "Surgeon", "Astronomer", "Fasting Specialist", 0) </SCRIPT>
  • 9. </HEAD> <BODY> <SCRIPT LANGUAGE="JavaScript"><!-- readCookie() document.writeln("<H1 ALIGN='LEFT'>"+"<img src=corruption.jpg width=980 height=120/>" +"<br>" +pageHeading+"</H1>"+"<hr>") document.writeln("<P ALIGN='RIGHT'><B>Questions: " +numberOfQuestions+"<BR>") document.writeln("Correct Answers: "+correctAnswers+"<BR>") document.writeln("Score: "+score+"</B>") document.writeln("<img ALIGN='RIGHT' src='co.jpg' width=150 height=300/>") if(currentQuestion >= qa.length) endQuiz() else askNextQuestion() // --></SCRIPT> </BODY> </HTML>