Reputation: 53
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>
Upvotes: 5
Views: 5389
Reputation: 1451
change the variable name which you have given "2et" and give string as a variable name it will work....
Upvotes: 1
Reputation: 43852
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.
Upvotes: 10