我想在浏览器中运行一个javascript文件,为此,我创建了一个index.html文件
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>javascript</title>
<script src="recamans.js" type="text/javascript">
</script>
</head>
<body>
</body>
</html>
并链接了我的JavaScript文件,如上所示。我包含的javascript文件是
let count = 1;
let sequence = [];
let numbers = [];
let index = 0;
let next;
function step() {
let next = index - count;
if( next < 0 || numbers[next]){
next = index + count;
}
numbers[next] = true;
sequence.push(next);
index = next;
count++;
}
function setup() {
let createCanvas = (600, 400);
numbers[next] = true;
sequence.push(index);
for( let i=0; i<10; i++){
step();
}
console.log(sequence);
}
setup();
但它不会在浏览器中产生任何输出。
答案 0 :(得分:0)
console.log()
不会输出到文档。您需要:
document.getElementById("myDiv").innerHTML = sequence;
示例:https://www.w3schools.com/code/tryit.asp?filename=FTLNWQF4PXQO
答案 1 :(得分:-1)
添加 document.write(sequence); 在console.log(sequence)之后;