jeudi 26 mars 2015

I want someone to changing my Javascript Quiz

I have a code that i used to developed a quiz and i don't need to change questions just the way they work on web browser. i need help on changing click question, next question and submit button and question papers one after the other nd % score. as well i need help to change the variables, functions and if statements to look different but do the same as this code:





< script >
var quiztitle = "Childrens Film and TV Quiz";
var quiz = [{
"question": "Who is this?",
"image": "boo.jpg",
"choices": [
"James P. Sullivan",
"Mike Wazowski",
"Boo",
"Randall Boggs"
],
"correct": "Boo",
}, {
"question": "What is the name of The Lion from The Chronicles of Narnia: The Lion, the Witch and the Wardrobe?",
"choices": [
"Peter",
"Edmund",
"MR.Tumnus",
"Aslan"
],
"correct": "Aslan",

}, {
"question": "Who is this from Toy Story?",
"image": "woody.jpg",
"choices": [
"Buzz Lightyear",
"Woody",
"Slinky Dog",
"Rex"
],
"correct": "Woody",
}, {
"question": "In waht house did the sorting hat almost put Harry Potter in?",
"choices": [
"Slytherin",
"Hufflepuff",
"Gryffindor",
"Ravenclaw"
],
"correct": "Slytherin",
}, {
"question": "Whitch fish from finding nemo has memory loss?",
"choices": [
"Nemo",
"Gill",
"Dory",
"Peach"
],
"correct": "Dory",
}, {
"question": "What does spongebobs house look like?",
"choices": [
"Rock",
"House shaped like an Easter Island head (Moai head)",
"Anchor",
"Pineapple"
],
"correct": "Pineapple",
}, {
"question": "Which Simpsopns charictore is missing?",
"image": "missing from simpsons family.jpg",
"choices": [
"Bart",
"Marge",
"Homer",
"Lisa"
],
"correct": "Bart",
}, {
"question": "Who says let's split up gang in Scooby Doo?",
"choices": [
"Fred",
"Daphne",
"Shaggy",
"Velma"
],
"correct": "Fred",
}, {
"question": "What is the colour of the blue peter badge?",
"choices": [
"Red and green ",
"Purple and Silver",
"Orange and Gold",
"Blue and White"
],
"correct": "Blue and White",
}, {
"question": "What cartoon character is famous for saying what's up duck?",
"choices": [
"Mickey Mouse",
"Fred Flintstone",
"Bugs Bunny",
"Tom and Jerry"
],

"correct": "Bugs Bunny",
}, ];

var currentquestion = 0,
score = 0,
submt = true,
picked;

$(document).ready(function() {
$("#submitbutton").hide();

function htmlEncode(value) {
return $(document.createElement('div')).text(value).html();
}


function addChoices(choices) {
if (typeof choices !== "undefined" && $.type(choices) == "array") {
$('#choice-block').empty();
for (var i = 0; i < choices.length; i++) {
$(document.createElement('li')).addClass('choice choice-box').attr('data-index', i).text(choices[i]).appendTo('#choice-block');
}
}
}

function nextQuestion() {
submt = true;
$('#question').text(quiz[currentquestion]['question']);
$('#pager').text('Question ' + Number(currentquestion + 1) + ' of ' + quiz.length);
if (quiz[currentquestion].hasOwnProperty('image') && quiz[currentquestion]['image'] != "") {
if ($('#question-image').length == 0) {
$(document.createElement('img')).addClass('question-image').attr('id', 'question-image').attr('src', quiz[currentquestion]['image']).attr('alt', htmlEncode(quiz[currentquestion]['question'])).insertAfter('#question');
} else {
$('#question-image').attr('src', quiz[currentquestion]['image']).attr('alt', htmlEncode(quiz[currentquestion]['question']));
}
} else {
$('#question-image').remove();
}
addChoices(quiz[currentquestion]['choices']);
setupButtons();


}


function processQuestion(choice) {
currentquestion++;
$("#submitbutton").hide();

if (currentquestion == quiz.length) {
endQuiz();
} else {

nextQuestion();
}

}


function setupButtons() {
$('.choice').on('mouseover', function() {});
$('.choice').on('mouseout', function() {});
$('.choice').on('click', function() {
choice = $(this).attr('data-index');
$('.choice').removeAttr('style').off('mouseout mouseover');
$(this).css({
'background-color': '#04B4AE'

});
if (quiz[currentquestion]['choices'][choice] == quiz[currentquestion]['correct']) {
$('.choice').eq(choice).css({});
score++;
} else {
$('.choice').eq(choice).css({});
}
$("#submitbutton").show();
if (submt) {
submt = false;
$('#submitbutton')
$("#submitbutton").click(function() {
$('.choice').off('click');
$(this).off('click');
processQuestion(choice);
});
}
})
}


function endQuiz() {
$('#question').empty();
$('#choice-block').empty();
$('#submitbutton').remove();
$(document.createElement('h2')).css({
'text-align': 'center',
'font-size': '6em'
}).text(Math.round(score / quiz.length * 100) + '%').insertAfter('#question');
}


function init() {

if (typeof quiztitle !== "undefined" && $.type(quiztitle) === "string") {
$(document.createElement('h1')).text(quiztitle).appendTo('#frame');
} else {
$(document.createElement('h1')).text("Quiz").appendTo('#frame');
}


if (typeof quiz !== "undefined" && $.type(quiz) === "array") {

$(document.createElement('p')).addClass('pager').attr('id', 'pager').text('Question 1 of ' + quiz.length).appendTo('#frame');

$(document.createElement('h2')).addClass('question').attr('id', 'question').text(quiz[0]['question']).appendTo('#frame');

if (quiz[0].hasOwnProperty('image') && quiz[0]['image'] != "") {
$(document.createElement('img')).addClass('question-image').attr('id', 'question-image').attr('src', quiz[0]['image']).attr('alt', htmlEncode(quiz[0]['question'])).appendTo('#frame');
}
$(document.createElement('p')).addClass('explanation').attr('id', 'explanation').html('&nbsp;').appendTo('#frame');

$(document.createElement('ul')).attr('id', 'choice-block').appendTo('#frame');


addChoices(quiz[0]['choices']);


$(document.createElement('div')).addClass('choice-box').attr('id', 'submitbutton').text('Next Question').css({
'font-weight': 700,
'color': '#222',
'padding': '30px 0',
}).appendTo('#frame');


$("#submitbutton").hide();
setupButtons();
}
}

init();
});

< /script>



<style type="text/css"> body {
background-image: url();
background-color: #69C;
}
</style> <center><div id="frame" role="content" > <div id="frame" role="content"> </center> <style type="text/css" media="all">
}
}
img.question-image {
display:block;
max-width:160px;
margin:10px auto;
border:0px solid #ccc;
width:100%;
height:auto;
}
}
</style>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ift.tt/kkyg93">
<html xmlns="http://ift.tt/lH0Osb">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Children Film and TV Quiz</title>
<script src="http://ift.tt/VW0zw3"></script>
</head>

<body>
<center>
<button onclick="myFunction()">Restart Quiz</button>
</center>

<script>
function myFunction() {
location.reload();
}
</script>
</body>

</html>



I need the code to be programmed in javascript


Aucun commentaire:

Enregistrer un commentaire