As a newcomer to JavaScript, I am trying to extract the values of 8 labels (text) and store them in an array of 8 numbers. My goal is to then identify the prime numbers within this array. While I have been able to create the array and display the labels in the HTML, I am struggling with transferring the values to the array. Any assistance on this matter would be greatly appreciated. Thank you!
The code for my solver button:
$('#btn1').click(function () {
var primes = [true, true, true, true, true, true, true, true];
var limit = Math.sqrt(8);
for (var i = 1; i < 8; i++) {
if (primes[i] === true) {
for (var j = i * i; j < 8; j += i) {
primes[j] = false;
}
}
}
for (var i = 1; i < 8; i++) {
if (primes[i] === true) {
console.log(i + " " + primes[i]);
}
}
});
The code for the labels:
<label>1. </label> <input id="input1" type="text"><br>
<label>2. </label> <input id="input2" type="text"><br>
<label>3. </label> <input id="input3" type="text"><br>
<label>4. </label> <input id="input4" type="text"><br>
<label>5. </label> <input id="input5" type="text"><br>
<label>6. </label> <input id="input6" type="text"><br>
<label>7. </label> <input id="input7" type="text"><br>
<label>8. </label> <input id="input8" type="text"><br>