here is my code! and it works but I'm not sure if it's written right so I want some feedback





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0












$begingroup$


I wrote this code and it works but I'm really not sure if it's written without any weird parts.
So I want your feedbacks. I will really appreciate all your comments. thanks!



Operation description : the questions are being showed in the console tap with player's score. it's questioning by prompt continually until the prompt input gets 'exit'. If the answer for each question is right then player's scores are counting up. but if not then it shows the same question over and over until the answer is right.



var Question = function(question,answers,correctAnswer){
this.question = question;
this.answers = answers;
this.correctAnswer = correctAnswer;
}
Question.prototype.score = 0;
Question.prototype.playersAnswer;

Question.prototype.logAll = function(){
console.log(this.question);
for(var i = 0; i < this.answers.length; i++){
console.log(i + " : " + this.answers[i]);
}
}
Question.prototype.askQuestions = function(){
Question.prototype.playersAnswer = prompt(this.question);
}
Question.prototype.checkIfRight = function (){
if(this.correctAnswer === Question.prototype.playersAnswer){
console.log("Correct Answer!");
Question.prototype.score++;
Question.prototype.logScore();
}
else if(Question.prototype.playersAnswer === "exit"){return 0;}
else {
console.log("Wrong! Try again :)");
Question.prototype.logScore();
return 'w';
}
}
Question.prototype.logScore = function(){
console.log("Your Score : " + Question.prototype.score
+ "n---------------------------------");
}

var q1 = new Question('What is the name of the course's teacher?',['John','Baek','Jonas'],'2');
var q2 = new Question('Is JavaScript the coolest language in the world?',['Yes','No'],'0');
var q3 = new Question('What language are you gonna learn about after?',
['C++','C','Java','Python','Node.js'],'4');
var questions = [q1,q2,q3];
function init(){
var n = Math.floor(Math.random() * 3);
questions[n].logAll();
questions[n].askQuestions();
questions[n].checkIfRight();

}

do {
var n = Math.floor(Math.random() * 3);
questions[n].logAll();
questions[n].askQuestions();
while(questions[n].checkIfRight() === 'w'){
questions[n].logAll();
questions.askQuestions();
};
}
while (q1.playersAnswer !== "exit");









share|improve this question









$endgroup$



migrated from stackoverflow.com 11 mins ago


This question came from our site for professional and enthusiast programmers.


















  • $begingroup$
    You can instal ESLint in your project, ESLint is a standard used by the biggest companies which use JavaScript. ESLint will throw warnings and errors which will tell you how to format and write your code by the standard, gives you suggestions and links with examples how is wrong and how is right to write your code and format it. You can learn more here: eslint.org I hope that helps, my JavaScript improved a lot after I started using the linting feature in all of my projects.
    $endgroup$
    – Todor Dimov
    22 mins ago










  • $begingroup$
    None of the things you’re changing at runtime on Question.prototype belong there. You can just use variables.
    $endgroup$
    – Ry-
    16 mins ago


















0












$begingroup$


I wrote this code and it works but I'm really not sure if it's written without any weird parts.
So I want your feedbacks. I will really appreciate all your comments. thanks!



Operation description : the questions are being showed in the console tap with player's score. it's questioning by prompt continually until the prompt input gets 'exit'. If the answer for each question is right then player's scores are counting up. but if not then it shows the same question over and over until the answer is right.



var Question = function(question,answers,correctAnswer){
this.question = question;
this.answers = answers;
this.correctAnswer = correctAnswer;
}
Question.prototype.score = 0;
Question.prototype.playersAnswer;

Question.prototype.logAll = function(){
console.log(this.question);
for(var i = 0; i < this.answers.length; i++){
console.log(i + " : " + this.answers[i]);
}
}
Question.prototype.askQuestions = function(){
Question.prototype.playersAnswer = prompt(this.question);
}
Question.prototype.checkIfRight = function (){
if(this.correctAnswer === Question.prototype.playersAnswer){
console.log("Correct Answer!");
Question.prototype.score++;
Question.prototype.logScore();
}
else if(Question.prototype.playersAnswer === "exit"){return 0;}
else {
console.log("Wrong! Try again :)");
Question.prototype.logScore();
return 'w';
}
}
Question.prototype.logScore = function(){
console.log("Your Score : " + Question.prototype.score
+ "n---------------------------------");
}

var q1 = new Question('What is the name of the course's teacher?',['John','Baek','Jonas'],'2');
var q2 = new Question('Is JavaScript the coolest language in the world?',['Yes','No'],'0');
var q3 = new Question('What language are you gonna learn about after?',
['C++','C','Java','Python','Node.js'],'4');
var questions = [q1,q2,q3];
function init(){
var n = Math.floor(Math.random() * 3);
questions[n].logAll();
questions[n].askQuestions();
questions[n].checkIfRight();

}

do {
var n = Math.floor(Math.random() * 3);
questions[n].logAll();
questions[n].askQuestions();
while(questions[n].checkIfRight() === 'w'){
questions[n].logAll();
questions.askQuestions();
};
}
while (q1.playersAnswer !== "exit");









share|improve this question









$endgroup$



migrated from stackoverflow.com 11 mins ago


This question came from our site for professional and enthusiast programmers.


















  • $begingroup$
    You can instal ESLint in your project, ESLint is a standard used by the biggest companies which use JavaScript. ESLint will throw warnings and errors which will tell you how to format and write your code by the standard, gives you suggestions and links with examples how is wrong and how is right to write your code and format it. You can learn more here: eslint.org I hope that helps, my JavaScript improved a lot after I started using the linting feature in all of my projects.
    $endgroup$
    – Todor Dimov
    22 mins ago










  • $begingroup$
    None of the things you’re changing at runtime on Question.prototype belong there. You can just use variables.
    $endgroup$
    – Ry-
    16 mins ago














0












0








0





$begingroup$


I wrote this code and it works but I'm really not sure if it's written without any weird parts.
So I want your feedbacks. I will really appreciate all your comments. thanks!



Operation description : the questions are being showed in the console tap with player's score. it's questioning by prompt continually until the prompt input gets 'exit'. If the answer for each question is right then player's scores are counting up. but if not then it shows the same question over and over until the answer is right.



var Question = function(question,answers,correctAnswer){
this.question = question;
this.answers = answers;
this.correctAnswer = correctAnswer;
}
Question.prototype.score = 0;
Question.prototype.playersAnswer;

Question.prototype.logAll = function(){
console.log(this.question);
for(var i = 0; i < this.answers.length; i++){
console.log(i + " : " + this.answers[i]);
}
}
Question.prototype.askQuestions = function(){
Question.prototype.playersAnswer = prompt(this.question);
}
Question.prototype.checkIfRight = function (){
if(this.correctAnswer === Question.prototype.playersAnswer){
console.log("Correct Answer!");
Question.prototype.score++;
Question.prototype.logScore();
}
else if(Question.prototype.playersAnswer === "exit"){return 0;}
else {
console.log("Wrong! Try again :)");
Question.prototype.logScore();
return 'w';
}
}
Question.prototype.logScore = function(){
console.log("Your Score : " + Question.prototype.score
+ "n---------------------------------");
}

var q1 = new Question('What is the name of the course's teacher?',['John','Baek','Jonas'],'2');
var q2 = new Question('Is JavaScript the coolest language in the world?',['Yes','No'],'0');
var q3 = new Question('What language are you gonna learn about after?',
['C++','C','Java','Python','Node.js'],'4');
var questions = [q1,q2,q3];
function init(){
var n = Math.floor(Math.random() * 3);
questions[n].logAll();
questions[n].askQuestions();
questions[n].checkIfRight();

}

do {
var n = Math.floor(Math.random() * 3);
questions[n].logAll();
questions[n].askQuestions();
while(questions[n].checkIfRight() === 'w'){
questions[n].logAll();
questions.askQuestions();
};
}
while (q1.playersAnswer !== "exit");









share|improve this question









$endgroup$




I wrote this code and it works but I'm really not sure if it's written without any weird parts.
So I want your feedbacks. I will really appreciate all your comments. thanks!



Operation description : the questions are being showed in the console tap with player's score. it's questioning by prompt continually until the prompt input gets 'exit'. If the answer for each question is right then player's scores are counting up. but if not then it shows the same question over and over until the answer is right.



var Question = function(question,answers,correctAnswer){
this.question = question;
this.answers = answers;
this.correctAnswer = correctAnswer;
}
Question.prototype.score = 0;
Question.prototype.playersAnswer;

Question.prototype.logAll = function(){
console.log(this.question);
for(var i = 0; i < this.answers.length; i++){
console.log(i + " : " + this.answers[i]);
}
}
Question.prototype.askQuestions = function(){
Question.prototype.playersAnswer = prompt(this.question);
}
Question.prototype.checkIfRight = function (){
if(this.correctAnswer === Question.prototype.playersAnswer){
console.log("Correct Answer!");
Question.prototype.score++;
Question.prototype.logScore();
}
else if(Question.prototype.playersAnswer === "exit"){return 0;}
else {
console.log("Wrong! Try again :)");
Question.prototype.logScore();
return 'w';
}
}
Question.prototype.logScore = function(){
console.log("Your Score : " + Question.prototype.score
+ "n---------------------------------");
}

var q1 = new Question('What is the name of the course's teacher?',['John','Baek','Jonas'],'2');
var q2 = new Question('Is JavaScript the coolest language in the world?',['Yes','No'],'0');
var q3 = new Question('What language are you gonna learn about after?',
['C++','C','Java','Python','Node.js'],'4');
var questions = [q1,q2,q3];
function init(){
var n = Math.floor(Math.random() * 3);
questions[n].logAll();
questions[n].askQuestions();
questions[n].checkIfRight();

}

do {
var n = Math.floor(Math.random() * 3);
questions[n].logAll();
questions[n].askQuestions();
while(questions[n].checkIfRight() === 'w'){
questions[n].logAll();
questions.askQuestions();
};
}
while (q1.playersAnswer !== "exit");






javascript object-oriented






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 29 mins ago







tae ha











migrated from stackoverflow.com 11 mins ago


This question came from our site for professional and enthusiast programmers.









migrated from stackoverflow.com 11 mins ago


This question came from our site for professional and enthusiast programmers.














  • $begingroup$
    You can instal ESLint in your project, ESLint is a standard used by the biggest companies which use JavaScript. ESLint will throw warnings and errors which will tell you how to format and write your code by the standard, gives you suggestions and links with examples how is wrong and how is right to write your code and format it. You can learn more here: eslint.org I hope that helps, my JavaScript improved a lot after I started using the linting feature in all of my projects.
    $endgroup$
    – Todor Dimov
    22 mins ago










  • $begingroup$
    None of the things you’re changing at runtime on Question.prototype belong there. You can just use variables.
    $endgroup$
    – Ry-
    16 mins ago


















  • $begingroup$
    You can instal ESLint in your project, ESLint is a standard used by the biggest companies which use JavaScript. ESLint will throw warnings and errors which will tell you how to format and write your code by the standard, gives you suggestions and links with examples how is wrong and how is right to write your code and format it. You can learn more here: eslint.org I hope that helps, my JavaScript improved a lot after I started using the linting feature in all of my projects.
    $endgroup$
    – Todor Dimov
    22 mins ago










  • $begingroup$
    None of the things you’re changing at runtime on Question.prototype belong there. You can just use variables.
    $endgroup$
    – Ry-
    16 mins ago
















$begingroup$
You can instal ESLint in your project, ESLint is a standard used by the biggest companies which use JavaScript. ESLint will throw warnings and errors which will tell you how to format and write your code by the standard, gives you suggestions and links with examples how is wrong and how is right to write your code and format it. You can learn more here: eslint.org I hope that helps, my JavaScript improved a lot after I started using the linting feature in all of my projects.
$endgroup$
– Todor Dimov
22 mins ago




$begingroup$
You can instal ESLint in your project, ESLint is a standard used by the biggest companies which use JavaScript. ESLint will throw warnings and errors which will tell you how to format and write your code by the standard, gives you suggestions and links with examples how is wrong and how is right to write your code and format it. You can learn more here: eslint.org I hope that helps, my JavaScript improved a lot after I started using the linting feature in all of my projects.
$endgroup$
– Todor Dimov
22 mins ago












$begingroup$
None of the things you’re changing at runtime on Question.prototype belong there. You can just use variables.
$endgroup$
– Ry-
16 mins ago




$begingroup$
None of the things you’re changing at runtime on Question.prototype belong there. You can just use variables.
$endgroup$
– Ry-
16 mins ago










0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217368%2fhere-is-my-code-and-it-works-but-im-not-sure-if-its-written-right-so-i-want-s%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown
























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Code Review Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217368%2fhere-is-my-code-and-it-works-but-im-not-sure-if-its-written-right-so-i-want-s%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Сан-Квентин

8-я гвардейская общевойсковая армия

Алькесар