Error in project: Uncaught SyntaxError: Unexpected token var
I am making a console with javascript but I have had problems to find out the source of the error. I've reviewed the code several times and couldn't figure out what's wrong. Any help is appreciated.
var logStack = 0;
var showTime = false;
var currDate = new Date();
var i = 0;
var tempStr = "temp";
function getLogStr(var lineNum) {
if(lineNum <= 10 & lineNum > 0) {
return document.getELementById("line" + lineNum);
} else {
tempSTr = "Invalid line!";
return tempStr;
}
}
function setLogStr(var newLog, var line) {
if(line <= 10 & line > 0) {
document.getELementById("line" + line).innerHTML = newLog;
} else {
console.log("Invalid line!");
}
}
function shiftLog(var line10) {
if(logStack == 10) {
for(i = 1;i <= 10;i++) {
setLogStr(i,getLogStr(i + 1));
}
setLogStr(10,line10);
} else {
console.log("There are free lines!");
}
}
function logOnConsole(var newLog) {
currDate = Date();
if(logStack == 10) {
shiftLog(new Date().getHours());
} else {
setLogStr(newLog, logSTack + 1);
logStack++;
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1" />
<title>Ice Console</title>
</head>
<body>
<div id="line1"></div>
<br />
<div id="line2"></div>
<br />
<div id="line3"></div>
<br />
<div id="line4"></div>
<br />
<div id="line5"></div>
<br />
<div id="line6"></div>
<br />
<div id="line7"></div>
<br />
<div id="line8"></div>
<br />
<div id="line9"></div>
<br />
<div id="line10"></div>
<br />
<input type="text" id="console" />
<input type="button" value="Run" />
</body>
</html>
1
Author: Gabriel C., 2017-02-18
1 answers
Removes all var
from function arguments, this is wrong syntax in JavaScript.
I.e. changes function getLogStr(var lineNum) {
to function getLogStr(lineNum) {
.
These variables such as lineNum
are declared by the function and are only available within the function (i.e. they are limited to the scope of the function).
2
Author: Sergio, 2017-02-18 15:41:29