Forgive me for the dumb question but I'm a beginner in using Javascript and I'm not sure if it's because of the IDE I'm using(which is Replit) or if there's a different rule in Javascript(as I'm a little bit more familiar with C# and would not be havingt this problem if I were using that).
But, I don't know how to display input to the window before I accept user-input. For example I have the following code that is part of a little game I'm creating where I ask trivia questions.
class Question {
constructor(t, oA, oB, oC, oD, ans) {
this.title = t;
this.optionA = oA;
this.optionB = oB;
this.optionC = oC;
this.optionD = oD
this.answer = ans;
}
displayEntireQuestion() {
console.log(`${this.title}`);
console.log(`A.${this.optionA}`);
console.log(`B.${this.optionB}`);
console.log(`C.${this.optionC}`);
console.log(`D.${this.optionD}`);
}
}
let Round1Questions = [
new Question("What was the most popular language of 2018?", "PHP", "JavaScript", "Ruby", "Python", "Javascript"),
new Question("What year did WW2 end in?", "1945",
"1939", "1978", "1942", "1945")
]
let question1 = Round1Questions[Math.floor(Math.random() * Round1Questions.length)];
question1.displayEntireQuestion();
console.log("Please enter the correct answer");
userAnswer = prompt();
if (userAnswer == question1.answer) {
console.log("Correct!");
} else {
console.log("Sorry, wrong answer.");
}
When I run this it automatically goes to the prompt command without displaying the question first. How can I fix this? I feel so dumb for asking this because I'm used to using C# in Visual Studio where the code executes line by line.
edit: Even if I put "Please enter the correct answer" in my prompt method, it still doesn't solve the issue of the question not being displayed first