0

I don't know who closed this question; but clearly it was never answered; maybe just to satisfy all question that are posted in this site; but clearly it did not match my question:: what a limp nodes is this...

But the Answer to this is a Map with empty key:

"use strict"
try{
  const fruits = new Map([["Banana",""],["Apples", ""], ["Orange"," "]]);

let text = "<h1>Fruits</h1>" + "<ul>";

fruits.forEach(function(value, key){
  text += "<li>" + key + value + "<br>" + "</li>" });

text +="</li> ";

document.getElementById('demo').innerHTML = text;
}
catch(err){
 document.getElementById('theError').innerHTML = err;
}

I was able to get an output with console.log with forEach but not with document.getElementById; also cant do with template literals on this... can somebody see or check this out or; this is something we need to improve with JS and to what ES?

sample below is stuck with one array result only and it did not loop, but at least.

<javascript>
"use strict"
try{
 const cars = new Array("Saab", "Volvo", "BMW");
 cars.sort;
 
 let theResult = document.getElementById('demo');
 cars.forEach(car => { theResult.innerHTML =car});

}
catch(err){
  document.getElementById('theError').innerHTML = err;
} 

</javascript>

Here is the HTML

<html>
<head>
   <title></title>
</head>
<body>
   <p id  ='demo'>
   <p id  ='theError'>

</body>
</html>
Troy Cura
  • 1
  • 2
  • `theResult.innerHTML = car;` sets the inner HTML of `theResult` to `car`. In the next iteration, `theResult.innerHTML = car;` sets the inner HTML of `theResult` to `car`. Yes, that’s the same operation, overwriting the result over and over. There is no appending in your code. `console.log` appends to the log. `theResult.insertAdjacentText("beforeend", car);` would append to the DOM. – Sebastian Simon Oct 12 '22 at 14:08
  • I can see a lot of forEach to function on this type... – Troy Cura Oct 12 '22 at 14:18
  • What do you mean by “function on this type”? What type? Please note that this issue is not about `forEach`. – Sebastian Simon Oct 12 '22 at 14:21
  • solution... what else. but I already found my answer somewhere else's... thanks heaps... "use strict" try{ const fruits = new Map([["Banana",""],["Apples", ""], ["Orange"," "]]); let text = "

    Fruits

    " + "
      "; fruits.forEach(function(value, key){ text += "
    • " + key + value + "
      " + "
    • " }); text +=" "; document.getElementById('demo').innerHTML = text; } catch(err){ document.getElementById('theError').innerHTML = err; }
    – Troy Cura Oct 14 '22 at 12:18

0 Answers0