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)
4 Respuestas
+ 3
Use <br> tag at the end of each temprate literal.
(` ... ${item.price} <br>`)
+ 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)
+ 1
Either use <br> like Chris Coder said or embed each in a paragraph like
(`<p>...${item.price}</p>`)
0
Thank you either, I will check and announce the result 😊