Task is simple write numbers from 1 to 99 and replace all numbers where: num (mod 3) =0 with each num (mod 5) =0 -> mat, num ( mod 3=0 && mod 5=0 ) with each mat, all others remains the same. That is easy but the formatting is horrible so I want to do this: insert a space between every number and place every "special" word (dividable by 3,5 or both) on a separate line. I know I have to use string.prototype.format but how exactly? here is my current code:
<html>
<body>
<p>Click the button to join two strings into one new string.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var text = [];
var res = " ";
for (i=1; i<100; i++){
if (i%3 == 0 && i%5 == 0){
text[i]= "SachMat ";
}
else if (i%3 == 0){
text[i]= 'sach ';
}
else if (i%5 == 0){
text[i]= 'mat ';
}
else {
text[i]= i;
}
var res = res.concat(text[i]);
}
document.getElementById("demo").innerHTML = res;
}
</script>
</body>
</html>