Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<!DOCTYPE html><html><body style="padding:20px;font-family:Arial"><div id="o"></div><script>const p=[{n:"Phone",price:699,s:true},{n:"Laptop",price:1299,s:false},{n:"Tablet",price:449,s:true}];const inStock=p.filter(x=>x.s);document.getElementById("o").innerHTML="<p>In stock: "+inStock.map(x=>x.n).join(", ")+"</p><p>Total: $"+inStock.reduce((a,x)=>a+x.price,0)+"</p>";</script></body></html>
Result
Open