It's not doing a new line?

var text = 'First number: ' + number1 + '\n' + ', Last number: ' + number2 + '.' ;

I have \n but it’s not doing any new line?

It sort of depends a little on how you are using the variable text after you define it. Can you give us the code where you actually use text too?

3 Likes

Here is code https://codepen.io/DKPK/pen/GRNWoWB

Yes, this is helpful. I don’t think fillText supports new lines, so you’ll have to figure out someway to implement that yourself. One option would be to split the string at the newline and then call fillText for each substring in the resultant array. Or instead of putting that entire text line in text, put the first part before the newline in one variable and the second part after the newline in another variable and then call fillText for each one.

There may also be some JS libraries that implement newlines in canvas that you could search for on github.

Good luck.

1 Like