Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialGeetinder Bath
3,373 PointsHi, can you please review my implementation of the same problem from my workspace and give me some reviews, you r awesom
if you dont have access to my workspace
questions.js
function Question (question,choice0,choice1,rightChoice){ this.question = question; this.choice0 = choice0; this.choice1 = choice1; this.rightChoice = rightChoice; }
quiz.js
function Quiz (qElement,a1Element,a2Element,counterElement,eoqElement){ this.questions = []; this.currentQuestion = 0; this.rightAnswers = 0; this.wrongAnswers = 0; this.qElement = qElement; this.a1Element = a1Element; this.a2Element = a2Element; this.counterElement = counterElement; this.eoqElement = eoqElement; }
Quiz.prototype.addQuestion = function (Question){
this.questions.push(Question);
}
Quiz.prototype.rightOrWrong = function (currentChoice){
if(currentChoice === this.questions[this.currentQuestion].rightChoice){
this.rightAnswers += 1;
}
else{
this.wrongAnswers += 1;
}
this.currentQuestion += 1;
if(this.currentQuestion === this.questions.length){
this.endOfQuiz();
}
else{
this.render();
}
} Quiz.prototype.counter = function(){ var currentQuestionNumber = this.currentQuestion + 1; var counter = "Question " + currentQuestionNumber + " of " + this.questions.length; return counter; } Quiz.prototype.endOfQuiz = function(){ this.eoqElement.innerHTML = "<h1>End of Awesome Quiz</h1><h2>You got " + this.rightAnswers + " Answer(s) Right and " + this.wrongAnswers + " Answer(s) Wrong.</h2>"; } Quiz.prototype.render = function(){ this.qElement.innerHTML = this.questions[this.currentQuestion].question; this.a1Element.innerHTML = this.questions[this.currentQuestion].choice0; this.a2Element.innerHTML = this.questions[this.currentQuestion].choice1; this.counterElement.innerHTML = this.counter(); }
app.js
qElement = document.getElementById("question"); a1Element = document.getElementById("choice0"); a2Element = document.getElementById("choice1"); counterElement = document.getElementById("progress"); eoqElement = document.getElementById("quiz"); guess0 = document.getElementById("guess0"); guess1 = document.getElementById("guess1");
var quiz = new Quiz(qElement,a1Element,a2Element,counterElement,eoqElement);
quiz.addQuestion(new Question("Who is president of Canada?","Justin Trudou","Narinder Modi",0)); quiz.addQuestion(new Question("Who is president of India?","Justin Trudou","Narinder Modi",1));
guess0.onclick = function(){quiz.rightOrWrong(0)}; guess1.onclick = function(){quiz.rightOrWrong(1)}; quiz.render();
Joshua Erskine
7,706 PointsJoshua Erskine
7,706 PointsHi Geetinder, try the Markdown Cheatsheet, which can be found when you click Add Comment. Or copy and paste the address from your Workspaces window.
Markdown is a short-hand syntax for easily converting text to HTML. Below are some popular examples of Markdown formatting. For more examples reference Markdown Basics for a more detailed overview.