I am trying to insert a hyphen "‐" between the even numbers in an array so if i have 43268356925485942568 it shows 432–6–83569254–8594–256–8. The numbers are randomly generated. I tried several things but no luck.
<body>
<div id="arrayDisp">
</div>
<div id="numbers">
</div>
<script>
var numbers = new Array(20);
var numbers2 = new Array(20)
for (var i = 0; i< numbers.length; i++)
{
numbers[i] = parseInt(Math.random() * 10);
}
document.getElementById("arrayDisp").innerHTML = numbers.join(" ");
for(var i in numbers)
{
if(i%2 == 0)
{
numbers2.push('‐',i);
}
else
{
numbers2.push(i);
}
}
document.getElementById("numbers").innerHTML = numbers2.join("");
</script>
</body>
Aucun commentaire:
Enregistrer un commentaire