Project error: Uncaught Syntaxerror: Unexpected token var

Asked

Viewed 13,558 times

1

I am making a console with javascript but I have had problems to discover the origin of the error. I have reviewed the code several times and could not find out what is 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 answer

2


Removes all the var of the arguments of the functions, this is wrong syntax in Javascript.

That is to say: changes function getLogStr(var lineNum) { for function getLogStr(lineNum) {.

These variables as lineNum are declared by the function and are only available within the function (ie: are limited to the scope of the function).

  • 1

    Thanks, it’s been a while since I programmed in javascript and was more used to Java, so I ended up not touching myself.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.