I was told that it's best to avoid using document.write()
as much as possible. So how would you suggest I handle this code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Debug</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script>
function writeTimesTable(num) {
for(let i = 1; i < 13; i++ ) {
let writeString = i + " * " + num + " = ";
writeString = writeString + (i * num);
writeString = writeString + "<br />";
document.write(writeString);
}
}
</script>
</head>
<body>
<script>
for(let i = 1; i <= 13; i++ ) {
document.write("<p>")
writeTimesTable(i)
document.write("</p>")
}
</script>
</body>
</html>
I've tried a innerHTML
but I keep getting an undefined
This is the code I used after
function writeTimesTable(num) {
for(let i = 1; i < 10; i++ ) {
let writeString = i + " * " + num + " = ";
writeString = writeString + (i * num);
writeString = writeString + "<br />";
document.write(writeString);
}
}
function newTable() {
for(let i = 1; i <= 10; i++ ) {
let para = document.getElementById("paragraph");
para.innerHTML = writeTimesTable(i)
}
}