如何清除JavaScript代码中的用户输入?

发布于 2025-01-21 12:30:41 字数 1076 浏览 1 评论 0原文

我正在使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不在是我 2025-01-28 12:30:41

我做了一些研究,我认为只有在Codehs Java和Python上才有可能。

I have done some research and I think its is only possible on Codehs Java and Python.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文