hisoka Posted March 10, 2016 Share Posted March 10, 2016 (edited) when I run this script : var counter = 10;while (counter > 0){document.write (counter + "<br>");counter--;} I get : 10 9 8 7 6 5 4 3 2 1 however when I delete "<br>" from the script above like this : var counter = 10;while (counter > 0){document.write (counter + );counter--;} an error is engendered : SyntaxError: expected expression, got ')' why when I deleted "<br>" an error is engendered ? Edited March 10, 2016 by hisoka Link to comment Share on other sites More sharing options...
dsonesuk Posted March 10, 2016 Share Posted March 10, 2016 Its expecting a text string, variable or number value to follow the plus symbol. Link to comment Share on other sites More sharing options...
hisoka Posted March 18, 2016 Author Share Posted March 18, 2016 so the + sign in document.write (counter + "<br>"); is for concatenation ? Link to comment Share on other sites More sharing options...
dsonesuk Posted March 18, 2016 Share Posted March 18, 2016 Yes! If text string follows variable of a numeric value, or a number value on its own, they will all become text and concatenate, else if followed by numeric type, addition will occur. 1 Link to comment Share on other sites More sharing options...
hisoka Posted March 18, 2016 Author Share Posted March 18, 2016 thank you Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now