Click here to Skip to main content
15,884,859 members
Home / Discussions / JavaScript
   

JavaScript

 
QuestionBest way to trace JavaScript Conflict Pin
ReverseAds10-Jan-21 20:35
ReverseAds10-Jan-21 20:35 
QuestionRe: Best way to trace JavaScript Conflict Pin
Sandeep Mewara10-Jan-21 21:13
mveSandeep Mewara10-Jan-21 21:13 
AnswerRe: Best way to trace JavaScript Conflict Pin
20212a15-Jan-21 8:16
20212a15-Jan-21 8:16 
AnswerRe: Best way to trace JavaScript Conflict Pin
F-ES Sitecore28-Jan-21 21:24
professionalF-ES Sitecore28-Jan-21 21:24 
Questionhow to convert a function in to arrow function Pin
Member 139980429-Jan-21 0:56
Member 139980429-Jan-21 0:56 
AnswerRe: how to convert a function in to arrow function Pin
Afzaal Ahmad Zeeshan9-Jan-21 4:35
professionalAfzaal Ahmad Zeeshan9-Jan-21 4:35 
SuggestionRe: how to convert a function in to arrow function Pin
Richard Deeming11-Jan-21 22:41
mveRichard Deeming11-Jan-21 22:41 
QuestionQuiz Issue Pin
Shobhit Rathour30-Dec-20 3:35
Shobhit Rathour30-Dec-20 3:35 
Hello we do develop a quiz
also have code but we want just quiz check which user click on mcq answer
function Quiz(questions) {
    this.score = 0;
    this.questions = questions;
    this.questionIndex = 0;
   
}

Quiz.prototype.getQuestionIndex = function() {
    return this.questions[this.questionIndex];
}

Quiz.prototype.guess = function(answer) {
    if(this.getQuestionIndex().isCorrectAnswer(answer)) {
       
        this.score++;
    }
   
    this.questionIndex++;
}

Quiz.prototype.isEnded = function() {
    return this.questionIndex === this.questions.length;
}


function Question(text, choices, answer) {
    this.text = text;
    this.choices = choices;
    this.answer = answer;
}

Question.prototype.isCorrectAnswer = function(choice) {
    return this.answer === choice;
    
}



function populate() {
    if(quiz.isEnded()) {
        showScores();
    }
    else {
        // show question
        var element = document.getElementById("question");
        element.innerHTML = quiz.getQuestionIndex().text;

        // show options
        var choices = quiz.getQuestionIndex().choices;
        for(var i = 0; i < choices.length; i++) {
            var element = document.getElementById("choice" + i);
            element.innerHTML = choices[i];
            guess("btn" + i, choices[i]);
        }

        showProgress();
    }
};

function guess(id, guess) {
    var button = document.getElementById(id);
    button.onclick = function() {
        quiz.guess(guess);
        populate();
    }
};


function showProgress() {
    var currentQuestionNumber = quiz.questionIndex + 1;
    var element = document.getElementById("progress");
    element.innerHTML = "Question " + currentQuestionNumber + " of " + quiz.questions.length;
};

function showScores() {
    var gameOverHTML = "<h1>Result</h1>";
    gameOverHTML += "<h2 id='score'> Your scores: " + quiz.score + "</h2>";
    var element = document.getElementById("quiz");
    element.innerHTML = gameOverHTML;
};

// create questions here
var questions = [
    new Question("शरीर से पसीना सबसे अधिक कब निकलता है", ["जब तापक्रम अधिक और हवा सुख हो", "जब तापक्रम अधिक और हवा आर्द्र हो","जब तापक्रम कम और हवा आर्द्र हो", "जब तापक्रम कम और हवा सुखी हो"], "जब तापक्रम अधिक और हवा आर्द्र हो"),
    new Question("Which language is used for styling web pages?", ["HTML", "JQuery", "CSS", "XML"], "CSS"),
    new Question("Which is not a JavaScript Framework?", ["Python Script", "JQuery","Django", "NodeJS"], "Django"),
    new Question("Which is used for Connect To Database?", ["PHP", "HTML", "JS", "All"], "PHP"),
    new Question("Webdevtrick.com is about..", ["Web Design", "Graphic Design", "SEO & Development", "All"], "All")
];

// create quiz
var quiz = new Quiz(questions);

// display quiz
populate();</pre>


modified 5-Jan-21 11:51am.

AnswerRe: Quiz Issue Pin
Afzaal Ahmad Zeeshan9-Jan-21 5:02
professionalAfzaal Ahmad Zeeshan9-Jan-21 5:02 
QuestionReplacing the eval() function with something faster, more safe Pin
jkirkerx21-Dec-20 7:52
professionaljkirkerx21-Dec-20 7:52 
AnswerRe: Replacing the eval() function with something faster, more safe Pin
Graham Breach21-Dec-20 8:27
Graham Breach21-Dec-20 8:27 
GeneralRe: Replacing the eval() function with something faster, more safe Pin
jkirkerx21-Dec-20 9:21
professionaljkirkerx21-Dec-20 9:21 
Questionhigher order functions Pin
atomattacker-png21-Dec-20 1:49
atomattacker-png21-Dec-20 1:49 
AnswerRe: higher order functions Pin
Richard MacCutchan21-Dec-20 2:06
mveRichard MacCutchan21-Dec-20 2:06 
GeneralRe: higher order functions Pin
atomattacker-png21-Dec-20 2:21
atomattacker-png21-Dec-20 2:21 
GeneralRe: higher order functions Pin
Richard MacCutchan21-Dec-20 3:13
mveRichard MacCutchan21-Dec-20 3:13 
GeneralRe: higher order functions Pin
Richard MacCutchan21-Dec-20 4:02
mveRichard MacCutchan21-Dec-20 4:02 
GeneralRe: higher order functions Pin
atomattacker-png21-Dec-20 4:36
atomattacker-png21-Dec-20 4:36 
GeneralRe: higher order functions Pin
Richard MacCutchan21-Dec-20 4:44
mveRichard MacCutchan21-Dec-20 4:44 
QuestionAttempting to pre-populate text field and mailto based on ID Pin
Member 1502531419-Dec-20 1:10
Member 1502531419-Dec-20 1:10 
QuestionLooking to run a PHP page in the background using pure Javascript Pin
jkirkerx17-Dec-20 13:50
professionaljkirkerx17-Dec-20 13:50 
AnswerRe: Looking to run a PHP page in the background using pure Javascript Pin
DerekT-P17-Dec-20 22:54
professionalDerekT-P17-Dec-20 22:54 
GeneralRe: Looking to run a PHP page in the background using pure Javascript Pin
jkirkerx18-Dec-20 6:10
professionaljkirkerx18-Dec-20 6:10 
GeneralRe: Looking to run a PHP page in the background using pure Javascript Pin
DerekT-P18-Dec-20 7:11
professionalDerekT-P18-Dec-20 7:11 
GeneralRe: Looking to run a PHP page in the background using pure Javascript Pin
jkirkerx18-Dec-20 7:53
professionaljkirkerx18-Dec-20 7:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.