Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Design

You could remake this using Object-Oriented-Programming. For example, you could make a Question object, like this.

function Question(description, choices, correctChoiceIndex) {
 this.description = description;
 this.choices = choices;
 this.correctChoiceIndex = correctChoiceIndex;
}

You could then extend it with some methods, like askQuestion. For example, you could do something like this (Using prompt and alert because I'm on mobile.)

Question.prototype.askQuestion = function() {
 return prompt("Choices:\n" + this.choices.join("\n"));
}

You could then supply an additional method, checkAnswer, to see if the user got the answer correct.

Question.prototype.checkAnswer = function() {
 if(parseInt(this.askQuestion(), 10) === this.correctChoiceIndex) {
 alert("You got the question right!");
 }
 else {
 alert("Sorry, wrong answer.");
 }
}

Nitpicks

Some of your naming is not great. For example, firstFunc is an awful name for a function. It doesn't describe the purpose of the function in any way.

Preferably, names for variables/functions/classes should exhibit the following characteristics:

  • Describe the variable/function/class in detail.
  • Not have unnecessary abbreviations.
  • Not be too short.
  • Not be too long. (Unless you're programming in .)

Most of your variable names exhibit these characteristics, I just saw a few, like submitBtn that could be expanded to something like submitButton.

Moving on, I saw this line I your code:

var index = [i]; 

It isn't used anywhere in it's scope, and even if it was used, it would serve no purpose at this point.

Finally, when using the increment, ++, and decrement, -- operators, remember the differences between how they're placed remember the differences between how they're placed.

Design

You could remake this using Object-Oriented-Programming. For example, you could make a Question object, like this.

function Question(description, choices, correctChoiceIndex) {
 this.description = description;
 this.choices = choices;
 this.correctChoiceIndex = correctChoiceIndex;
}

You could then extend it with some methods, like askQuestion. For example, you could do something like this (Using prompt and alert because I'm on mobile.)

Question.prototype.askQuestion = function() {
 return prompt("Choices:\n" + this.choices.join("\n"));
}

You could then supply an additional method, checkAnswer, to see if the user got the answer correct.

Question.prototype.checkAnswer = function() {
 if(parseInt(this.askQuestion(), 10) === this.correctChoiceIndex) {
 alert("You got the question right!");
 }
 else {
 alert("Sorry, wrong answer.");
 }
}

Nitpicks

Some of your naming is not great. For example, firstFunc is an awful name for a function. It doesn't describe the purpose of the function in any way.

Preferably, names for variables/functions/classes should exhibit the following characteristics:

  • Describe the variable/function/class in detail.
  • Not have unnecessary abbreviations.
  • Not be too short.
  • Not be too long. (Unless you're programming in .)

Most of your variable names exhibit these characteristics, I just saw a few, like submitBtn that could be expanded to something like submitButton.

Moving on, I saw this line I your code:

var index = [i]; 

It isn't used anywhere in it's scope, and even if it was used, it would serve no purpose at this point.

Finally, when using the increment, ++, and decrement, -- operators, remember the differences between how they're placed.

Design

You could remake this using Object-Oriented-Programming. For example, you could make a Question object, like this.

function Question(description, choices, correctChoiceIndex) {
 this.description = description;
 this.choices = choices;
 this.correctChoiceIndex = correctChoiceIndex;
}

You could then extend it with some methods, like askQuestion. For example, you could do something like this (Using prompt and alert because I'm on mobile.)

Question.prototype.askQuestion = function() {
 return prompt("Choices:\n" + this.choices.join("\n"));
}

You could then supply an additional method, checkAnswer, to see if the user got the answer correct.

Question.prototype.checkAnswer = function() {
 if(parseInt(this.askQuestion(), 10) === this.correctChoiceIndex) {
 alert("You got the question right!");
 }
 else {
 alert("Sorry, wrong answer.");
 }
}

Nitpicks

Some of your naming is not great. For example, firstFunc is an awful name for a function. It doesn't describe the purpose of the function in any way.

Preferably, names for variables/functions/classes should exhibit the following characteristics:

  • Describe the variable/function/class in detail.
  • Not have unnecessary abbreviations.
  • Not be too short.
  • Not be too long. (Unless you're programming in .)

Most of your variable names exhibit these characteristics, I just saw a few, like submitBtn that could be expanded to something like submitButton.

Moving on, I saw this line I your code:

var index = [i]; 

It isn't used anywhere in it's scope, and even if it was used, it would serve no purpose at this point.

Finally, when using the increment, ++, and decrement, -- operators, remember the differences between how they're placed.

deleted 84 characters in body
Source Link
Ethan Bierlein
  • 15.9k
  • 4
  • 60
  • 146

Design

You could remake this using Object-Oriented-Programming. For example, you could make a Question object, like this.

function Question(description, choices, correctChoiceIndex) {
 this.description = description;
 this.choices = choices;
 this.correctChoiceIndex = correctChoiceIndex;
}

You could then extend it with some methods, like askQuestion. For example, you could do something like this (Using prompt and alert because I'm on mobile.)

Question.prototype.askQuestion = function() {
 return prompt("Choices:\n" + this.choices.join("\n"));
}

You could then supply an additional method, checkAnswer, to see if the user got the answer correct.

Question.prototype.checkAnswer = function() {
 if(parseInt(this.askQuestion(), 10) === this.correctChoiceIndex) {
 alert("You got the question right!");
 }
 else {
 alert("Sorry, wrong answer.");
 }
}

Nitpicks

Some of your naming is not great. For example, firstFunc is an awful name for a function. It doesn't describe the purpose of the function in any way.

Preferably, names for variables/functions/classes should exhibit the following characteristics:

  • Describe the variable/function/class in detail.
  • Not have unnecessary abbreviations.
  • Not be too short.
  • Not be too long. (Unless you're programming in .)

Most of your variable names exhibit these characteristics, I just saw a few, like submitBtn that could be expanded to something like submitButton.

Moving on, I saw this line I your code:

var index = [i]; 

It isn't used anywhere in it's scope, and even if it was used, it would serve no purpose at this point.

Finally, when using the increment, ++, and decrement, -- operators, remember the differences between how they're placed .

Design

You could remake this using Object-Oriented-Programming. For example, you could make a Question object, like this.

function Question(description, choices, correctChoiceIndex) {
 this.description = description;
 this.choices = choices;
 this.correctChoiceIndex = correctChoiceIndex;
}

You could then extend it with some methods, like askQuestion. For example, you could do something like this (Using prompt and alert because I'm on mobile.)

Question.prototype.askQuestion = function() {
 return prompt("Choices:\n" + this.choices.join("\n"));
}

You could then supply an additional method, checkAnswer, to see if the user got the answer correct.

Question.prototype.checkAnswer = function() {
 if(parseInt(this.askQuestion(), 10) === this.correctChoiceIndex) {
 alert("You got the question right!");
 }
 else {
 alert("Sorry, wrong answer.");
 }
}

Design

You could remake this using Object-Oriented-Programming. For example, you could make a Question object, like this.

function Question(description, choices, correctChoiceIndex) {
 this.description = description;
 this.choices = choices;
 this.correctChoiceIndex = correctChoiceIndex;
}

You could then extend it with some methods, like askQuestion. For example, you could do something like this (Using prompt and alert because I'm on mobile.)

Question.prototype.askQuestion = function() {
 return prompt("Choices:\n" + this.choices.join("\n"));
}

You could then supply an additional method, checkAnswer, to see if the user got the answer correct.

Question.prototype.checkAnswer = function() {
 if(parseInt(this.askQuestion(), 10) === this.correctChoiceIndex) {
 alert("You got the question right!");
 }
 else {
 alert("Sorry, wrong answer.");
 }
}

Nitpicks

Some of your naming is not great. For example, firstFunc is an awful name for a function. It doesn't describe the purpose of the function in any way.

Preferably, names for variables/functions/classes should exhibit the following characteristics:

  • Describe the variable/function/class in detail.
  • Not have unnecessary abbreviations.
  • Not be too short.
  • Not be too long. (Unless you're programming in .)

Most of your variable names exhibit these characteristics, I just saw a few, like submitBtn that could be expanded to something like submitButton.

Moving on, I saw this line I your code:

var index = [i]; 

It isn't used anywhere in it's scope, and even if it was used, it would serve no purpose at this point.

Finally, when using the increment, ++, and decrement, -- operators, remember the differences between how they're placed .

deleted 84 characters in body
Source Link
Ethan Bierlein
  • 15.9k
  • 4
  • 60
  • 146

Design

You could remake this using Object-Oriented-Programming. For example, you could make a Question object, like this.

function Question(description, choices, correctChoiceIndex) {
 this.description = description;
 this.choices = choices;
 this.correctChoiceIndex = correctChoiceIndex;
}

You could then extend it with some methods, like askQuestion. For example, you could do something like this (Using prompt and alert because I'm on mobile.)

Question.prototype.askQuestion = function() {
 return prompt("Choices:\n" + this.choices.join("\n"));
}

You could then supply an additional method, checkAnswer, to see if the user got the answer correct.

Question.prototype.checkAnswer = function() {
 if(parseInt(this.askQuestion(), 10) === this.correctChoiceIndex) {
 alert("You got the question right!");
 }
 else {
 alert("Sorry, wrong answer.");
 }
}

While this is far off from your cool DOM manipulation, I hope this answer helped a little.

You could remake this using Object-Oriented-Programming. For example, you could make a Question object, like this.

function Question(description, choices, correctChoiceIndex) {
 this.description = description;
 this.choices = choices;
 this.correctChoiceIndex = correctChoiceIndex;
}

You could then extend it with some methods, like askQuestion. For example, you could do something like this (Using prompt and alert because I'm on mobile.)

Question.prototype.askQuestion = function() {
 return prompt("Choices:\n" + this.choices.join("\n"));
}

You could then supply an additional method, checkAnswer, to see if the user got the answer correct.

Question.prototype.checkAnswer = function() {
 if(parseInt(this.askQuestion(), 10) === this.correctChoiceIndex) {
 alert("You got the question right!");
 }
 else {
 alert("Sorry, wrong answer.");
 }
}

While this is far off from your cool DOM manipulation, I hope this answer helped a little.

Design

You could remake this using Object-Oriented-Programming. For example, you could make a Question object, like this.

function Question(description, choices, correctChoiceIndex) {
 this.description = description;
 this.choices = choices;
 this.correctChoiceIndex = correctChoiceIndex;
}

You could then extend it with some methods, like askQuestion. For example, you could do something like this (Using prompt and alert because I'm on mobile.)

Question.prototype.askQuestion = function() {
 return prompt("Choices:\n" + this.choices.join("\n"));
}

You could then supply an additional method, checkAnswer, to see if the user got the answer correct.

Question.prototype.checkAnswer = function() {
 if(parseInt(this.askQuestion(), 10) === this.correctChoiceIndex) {
 alert("You got the question right!");
 }
 else {
 alert("Sorry, wrong answer.");
 }
}
Source Link
Ethan Bierlein
  • 15.9k
  • 4
  • 60
  • 146
Loading
default

AltStyle によって変換されたページ (->オリジナル) /