how to add line break in documnet.write output in JS | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how to add line break in documnet.write output in JS

Every Item should print in a single line basket = [ {id:0, name: "pen",price:100}, {id:1, name: "book",price:200}, {id:2,name: "notebook",price:80}, {id:3,name: "pencil",price:60}, {id:4,name: "bill",price:110}, {id:5,name: "mobile",price:30} ] sum = 0 postpayment = basket.filter((item)=>{ if (item.price < 100){ document.write(`product with 10$ shiping: ${item.name}`) item.price += 10 } document.write(`product without shiping: ${item.name}`) sum+=item.price }) document.write("the Total apyment with shiping is: ", sum)

27th Feb 2024, 8:34 PM
Meiqdad Hassani
Meiqdad Hassani - avatar
4 Answers
+ 3
Use <br> tag at the end of each temprate literal. (` ... ${item.price} <br>`)
27th Feb 2024, 9:38 PM
Chris Coder
Chris Coder - avatar
+ 1
or if you are going to do this multiple times, define your own println function. function println(...x){ document.write(x.join(' ')+'<br>') } basket = [ {id:0, name: "pen",price:100}, {id:1, name: "book",price:200}, {id:2,name: "notebook",price:80}, {id:3,name: "pencil",price:60}, {id:4,name: "bill",price:110}, {id:5,name: "mobile",price:30} ] sum = 0 postpayment = basket.filter((item)=>{ if (item.price < 100){ println(`product with 10$ shiping: ${item.name}`) item.price += 10 } println(`product without shiping: ${item.name}`) sum+=item.price }) println("The total payment with shiping is: ", sum)
28th Feb 2024, 4:41 AM
Bob_Li
Bob_Li - avatar
+ 1
Either use <br> like Chris Coder said or embed each in a paragraph like (`<p>...${item.price}</p>`)
29th Feb 2024, 8:32 PM
IAmSupreme
IAmSupreme - avatar
0
Thank you either, I will check and announce the result 😊
28th Feb 2024, 9:34 AM
Meiqdad Hassani
Meiqdad Hassani - avatar