Question: Need help with my javascript code which some numbers are missing from the table output such as 10, 21, 32, 43, etc. function isPrime(num) {

Need help with my javascript code which some numbers are missing from the table output such as 10, 21, 32, 43, etc.

function isPrime(num) {

for (var i = 2; i

if (num % i === 0) return false;

return num > 1;

}

function generateTable() {

var limit = window.prompt("What is the loop maximum (between 1 and 500)?");

if (limit 500) {

alert("Invalid input limit, setting to default value 100");

limit = 100;

}

var textCode = `

Below is a table that was created dynamically, showing the

sequence of numbers from 1 to ${limit} with all of the Prime Numbers

highlighted blue (or in Bootstrap terms using the

class="bg-primary text-white")

`

var tableCode = `

`;

for (let i = 0; i

tableCode += `

`;

var k = i;

for (let j = i; j

if (isPrime(i)) {

tableCode += `

`;

}

else tableCode += `

`;

i++;

if (i > limit) break;

}

tableCode += `

`;

}

tableCode += `

${i} ${i}

`;

document.getElementById("list_placeholder").innerHTML = textCode;

document.getElementById("primeTable").innerHTML = tableCode;

}

Output

Need help with my javascript code which some numbers are missing from

0 1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 33 34 35 36 37 38 39 40 41 42 44 45 46 47 48 49 50 51 52 53 55 56 57 58 59 60 61 62 63 64 66 67 68 69 59 | 70 71 72 73 74 75 77 78 79 80 81 82 83 84 85 86 88 89 90 91 92 93 94 95 96 97 99 100 101 102 103 104 105 106 107 108 110 on 111 112 113 114 115 116 117 118 8 | 1 119 121 122 123 124 125 126 127 128 129 130 132 133 134 135 136 137 138 139 140 141 143 144 145 146 147 148 149 150

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!