admin 管理员组文章数量: 1086019
Im a beginner programmer and im experiencing some issues loading javascript code on my browser. Are there any errors in my code? or could it be an issue with my puter. If it helps: im using OS Sierra, Google Chrome, Atom editor.
Thanks!!
HTML code:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<title>A* Algorithm</title>
<h1>This is the A* pathfinding algorithm</h1>
<script src ="astar.js"> </script>
</body>
</html>
Javascript code:
var cols = 5;
var rows = 5;
var grid = new Array(cols);
function setup() {
createCanvas(400, 400);
console.log("A*");
for (var i = 0; i < cols; i++) {
grid[i] = new Array(rows);
}
for (var i = 0; i < cols; i++) {
for (var j = 0; i < row; j++) {
grid[i][j] = new Spot();
}
}
console.log(grid);
}
function draw () {
background(0);
}
Im a beginner programmer and im experiencing some issues loading javascript code on my browser. Are there any errors in my code? or could it be an issue with my puter. If it helps: im using OS Sierra, Google Chrome, Atom editor.
Thanks!!
HTML code:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<title>A* Algorithm</title>
<h1>This is the A* pathfinding algorithm</h1>
<script src ="astar.js"> </script>
</body>
</html>
Javascript code:
var cols = 5;
var rows = 5;
var grid = new Array(cols);
function setup() {
createCanvas(400, 400);
console.log("A*");
for (var i = 0; i < cols; i++) {
grid[i] = new Array(rows);
}
for (var i = 0; i < cols; i++) {
for (var j = 0; i < row; j++) {
grid[i][j] = new Spot();
}
}
console.log(grid);
}
function draw () {
background(0);
}
Share
Improve this question
asked Feb 17, 2017 at 0:38
Alberto ArriagaAlberto Arriaga
111 gold badge1 silver badge2 bronze badges
2
- This is the exact code, right? – Umair Khan Commented Feb 17, 2017 at 0:42
- any errors on console? – Ajay Narain Mathur Commented Feb 17, 2017 at 0:42
3 Answers
Reset to default 2You have to call this Javascript function somewhere in any event there are plenty of ways, here the simplest one. However, additionally you haven`t defined the createCanvas function. hope it helps
<!DOCTYPE html>
<html>
<head>
<title>A* Algorithm</title>
</head>
<body onload="setup()">
<h1>This is the A* pathfinding algorithm</h1>
<script src="astar.js"> </script>
</body>
</html>
There is nothing wrong with your code, given that you script is named correctly and is in the same directory as you HTML file.
The cause, however, may be that you never call neither of you methods, you just construct them.
Simply including the script is not enough for the methods to run. To execute the function setup
simply add the following code to the end of your current script.
setup();
Steps:
Make sure your javascript and the html file is in the same folder. I notice that the part to your file (src ="astar.js") is the same as the name of your file.
Check the javascript console in the browser. One of the most effective ways to program is learning from your error messages. Javascript error messages can be reached view>>Developer>>Javascript console. When you are in the javascript console, run the code again and check for errors and go from there.
Cheers!
本文标签: htmlJavascript not loading in browserStack Overflow
版权声明:本文标题:html - Javascript not loading in browser - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1744076882a2529515.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论