如何清除JavaScript代码中的用户输入?
我正在使用Codehs中的JavaScript来创建一个10个问题的测验,要求每个问题中的用户输入。关于第四个问题之后,用户必须向下滚动浏览问题,以查看他们必须回答的下一个问题。这是非常不便的,可能会很烦人。
这是一张必须向下滚动以获取用户当前正在回答的问题的图片。 我正在尝试找到一种方法来清除用户在JavaScript Codehs中的每个问题之后的输入时间。
这是我的代码以供参考:
/* Asks the user questions and determines if the user's
input answers are emo (or correct) or not. */
function quiz(){
var score = 0;
for (var i = 0; i < questions.length; i++){
var answer = readLine(questions[i]);
if(answer == correct[i]){
println("Great!");
score++;
} else {
println("That's not very emo of you, next question!");
}
}
/*This variable calculates how emo the user is
based on the number of correct answers. */
var calculate = score * 100 / questions.length;
println("You are: " + calculate + "% emo! Congratulations." );
}
I'm using Javascript in CodeHS to create a 10-question quiz asking for user input in each question. After about the fourth question, the user must scroll down through the questions to see the next question they'll have to answer. This is very inconvenient and can get annoying.
Here is a picture of having to scroll down to get to the question the user currently is answering.
I'm trying to find a way to clear the user input after each question in Javascript CodeHS, so the user will only be able to see the question they're currently answering, without having to scroll down each time.
Here is my code for reference:
/* Asks the user questions and determines if the user's
input answers are emo (or correct) or not. */
function quiz(){
var score = 0;
for (var i = 0; i < questions.length; i++){
var answer = readLine(questions[i]);
if(answer == correct[i]){
println("Great!");
score++;
} else {
println("That's not very emo of you, next question!");
}
}
/*This variable calculates how emo the user is
based on the number of correct answers. */
var calculate = score * 100 / questions.length;
println("You are: " + calculate + "% emo! Congratulations." );
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我做了一些研究,我认为只有在Codehs Java和Python上才有可能。
I have done some research and I think its is only possible on Codehs Java and Python.