QuestionHow do i make a space between vars in JavaScript?

Posts 1–7 of 7 · Page 1 of 1
How do i make a space between vars in JavaScript?
hey guys, I don't actually know whether this is supposed to be in this forum or not. anyways, here is the code and how it looks like if opening it in the browser. im a total noob so don't be triggered XD im trying to get a space between the vars.
Code:
var r1 ="999999999999999999999999999999999999999999999999999999999999999999999"; // makes var with numbers
var l1 = r1.length; // makes a var. it doesnt calculate it just counts the length of the numbers. this is 69 because there are 69  9's
document.write(l1); // it writes it on your screen/executes the code? im not sure what is this im 12
var r2 ="moop"; // makes a var with letters by using "" i think. i still use it for numbers aswell anyway.
var s1 = r2.substring(1, 4) // it only starts showing from the second letter to the fourth. that will make oop
document.write(s1); // same as the above. only its a different var





Thanks

- - - Updated - - -

It might be hard to read the code btw, but I attached another image so you can easily see the problem and the code


- - - Updated - - -

still looking for answers
what exactly is the question?
Quote Originally Posted by MikeRohsoft View Post
what exactly is the question?
well, im noob so i dont even know it that well,
but since i used length, adding a space to the number that displays wont matter, since then it will simply show 70 instead of 69
im probably looking for a space that doesnt actually count with length. so i will have a space between 69 and oop yet it shouldnt change the 69 to 70

- - - Updated - - -

Quote Originally Posted by heiron70 View Post
What do you mean by space? the space in javascript is this "&nbsp"
maybe that could work, but ill search first on how I should use it since I don't actually know how.
since I have tried using it real quick but everywhere I place it, whatever comes after &nbsp doesn't display?
Quote Originally Posted by doger057 View Post
well, im noob so i dont even know it that well,
but since i used length, adding a space to the number that displays wont matter, since then it will simply show 70 instead of 69
im probably looking for a space that doesnt actually count with length. so i will have a space between 69 and oop yet it shouldnt change the 69 to 70

- - - Updated - - -


maybe that could work, but ill search first on how I should use it since I don't actually know how.
since I have tried using it real quick but everywhere I place it, whatever comes after * doesn't display?
oohh, now i understand what u want xD sweet
i think you are trying to do that:
Code:
var r1 ="999999999999999999999999999999999999999999999999999999999999999999999"; 
var l1 = r1.length; 

var r2 ="moop"; 
var s1 = r2.substring(1, 4);

document.write(l1 + " " + s1);
if u want to create a "line feed" you have to replace " " with "<br>"
What do you mean by space? the space in javascript is this "&nbsp"
Mike was correct sorry didn't understand the question
Code:
document.write( "+(var1)+ " " + (var2)+ " " + (var3)+"); /* another way
and yes <br> is line feed
With ES6 we have what we call Template Strings. It is the same logic but mor readable. Example

Code:
const name = "John";
console.log(`Hello, ${name}!`);
// Prints: Hello, John!
And you can do logic too

Code:
console.log(`I am ${2019-1991} years old.`);
// Prints: I am 28 years old.
Good coding
Posts 1–7 of 7 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?