Question
Step #5 Add code that clears any previous text from the message label. Then code a loop that iterates through the numbers from 1 to
Step #5 Add code that clears any previous text from the message label. Then code a loop that iterates through the numbers from 1 to the number entered by the user. Within the loop the isPrimeNumer() function should be called for each number. Then if the number is prime it should be added to the text that will be displayed in the message label. If isnt prime the code should continue with the next iteration of the loop.
Find Prime Numbers
"use strict"; $(document).ready(function(){ var isPrimeNumber = function(number) { var isPrime = (number < 2) ? false: true; // set default return value for (var i = 2; i < number; i++) { if( number % i === 0 ) isPrime = false; break; } return isPrime; }; $("#calculate").click( function() { var number = parseInt( $("#number").val() ); if ( isNaN(number) ) { $("#message").text( "Please enter a number." ); } else { // STEP #4 Comment out call statement and decision logic /* var isPrime = isPrimeNumber( number );
if ( isPrime === true ) { $("#message").text( number + " is a prime number." ); } else { $("#message").text( number + " is NOT a prime number." ); } */ // End STEP #4 // STEP #5 // End STEP #5 } $("#number").focus(); $("#number").select(); }); $("#number").focus(); });
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started