Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax Error: Missing Exponent in Javascript

Tags:

javascript

I have been getting syntax error. Missing exponent everytime I run my Javascript.

<script type="text/javascript">

function randomendtime(len) {
 var chars = ["10.202", "11.121", "12.101", "13.111", "14.121", "15.097", "18.142", "20.926"];
 return chars[ Math.floor(Math.random() * chars.length)];
}

var 2et = randomendtime(1);

document.write('<script type="text/javascript" src="http://www.example.com/' + 2et + '"><\/script>');

</script>
like image 814
user2885003 Avatar asked Oct 16 '13 04:10

user2885003


1 Answers

Your variable name 2et is invalid; JavaScript variables names can contain numbers, but may not start with them.

The reason you are getting an error about exponents is because JavaScript number literals may be written in scientific notation (e.g. 2e3, or 2000). Whichever JavaScript engine was running this code parsed the variable name as a malformed number literal, hence the error.

like image 156
Alexis King Avatar answered Oct 02 '22 23:10

Alexis King