【发布时间】:2022-12-19 15:54:31
【问题描述】:
我有一个简单的问题,我的项目是一个快速的 4 个选项答案,显示单选按钮和图片,现在我将图片和答案存储在一个文本文件中,这样我的 JS 会检测它读取的内容,然后将其传递给 HTML ,现在我使用这个函数来随机选择一条线:
fetch('./Test.txt', {
credentials: 'same-origin',
mode: 'same-origin',
}) // reads the file as a buffer
.then(function(response) {
return response.text();
})
.then(function(data) {
a = data
a = a.toString() // makes the buffer into a readable string
a = a.split('\n') // makes all the items in the list
randomNum = Math.floor(Math.random() * {The number of lines that you have in the text file}) // makes a math equation to get a random line from the text file
现在我如何检测randomNum是否通过了已经通过的行?或者比方说,我如何检查函数 randomNum 是否传递了已传递的行?
先感谢您
【问题讨论】:
-
忘了提到 `a[randomNum]` 给你一个随机行。
-
@UsithaIndeewara,我要问的是,当我得到第 1 行时,它已显示/运行,我如何存储 cookie 以告诉 JS 该用户已获得第 1 行,并告诉 JS不再为该用户显示行号 1?
-
抱歉,如果您不明白我的问题,我的问题是,我如何存储一个 cookie 来检查该用户是否得到了第 7 行,并且不再为用户显示它?
标签: javascript html node.js if-statement fetch