In: Computer Science
Using HTML and JavaScript, receive a positive number, n, and output all prime numbers that are smaller than n and have a digit 7. For example, if n is 100, the program should output 7, 17, 37, 47, 67, 71, 73, 79, and 97.
CODE IN JAVASCRIPT:
const number=parseInt(prompt("Enter the value of n : ")); //this will create a dialogue box which prompts when we take input
if(number==1)
{
console.log("The number is neither prime nor compsite")
}
for(let i=2; i<=number ;i++){ //checking for each integer between 2 to number
var count=0; //if this count changes to 1 for a number then the number is not prime
for(let j=2;j<=i/2;j++)
{
if(i%j==0)
{
count=1;
break;
}
}
if(count==0) //this means i is prime
{
var num=i; //this num is used to find all the integer with number 7
while(num!=0)
{
if(num%10==7) //checking condition if there is 7 in the number
{
console.log(i);
break;
}
num=num/10;
}
}
}
OUTPUT SNIPPET: