0

I have an assignment for school that I need to complete, these are the criteria, Count every number 0 - 35 Count every number 0 - 50, start from 30 and stop at 50 Count by 5's 0 - 50 Count down from 10 to 0 Count down from 100 - 0 by 10's Count every odd number from 1-30 all doing that with for loops so here is what i have so far, and for some reason it is not working

 <html>
<body>
<script>
for (int i = 0; i < 36; i++){ 
document.write(i);
}
</script>
</body>
</html>

my question is what am I doing wrong? it comes up with an unexpected identifier but thats all it says.

asked Nov 21, 2016 at 22:46
0

3 Answers 3

3

You can't declare a data type (int) in JavaScript. JavaScript is a loosely-typed language. There are only strings, numbers, booleans as primitive data types and the type you get is dependent on how you implicitly (or explicitly) use them.

Here, the variable i is initialized to 0, which is a valid number. When the JavaScript runtime sees you attempting to add to it, it allows that because it has implicitly known that i should be categorized as a number:

for (var i = 0; i < 36; i++){ 
 document.write(i);
}
// And, just for fun...
var a = 5;
var b = "5";
console.log("a's type is: " + typeof a);
console.log("b's type is: " + typeof b);
// But, you can coerce a value into a different type:
console.log("parseInt(b) results in: " + typeof parseInt(b));
console.log('a + "" results in: ' + typeof (a + ""));

Here's some good reading on the subject.

answered Nov 21, 2016 at 22:49
Sign up to request clarification or add additional context in comments.

Comments

2

there is no type called 'int' in javascript use 'var'

for (var i = 0; i < 36; i++){ 
 document.write(i);
}
answered Nov 21, 2016 at 22:49

Comments

2

int is no good in Javascript. Everything is defined as var. Try:

for (var i = 0; i < 36; i++){ 
 document.write(i);
}
answered Nov 21, 2016 at 22:50

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.