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 objective-c.)
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 objective-c.)
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 objective-c.)
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 objective-c .)
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 objective-c .)
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.");
}
}
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.");
}
}