Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

Are layers of support identified for students who struggle?

Answered: 1 week ago

Question

What is topology? Explain with examples

Answered: 1 week ago