<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Prime Checker</title> <style> body { font-family: Arial, sans-serif; text-align: center; } input { width: 200px; height: 40px; font-size: 20px; } button { width: 100px; height: 40px; font-size: 20px; } p { font-size: 24px; color: green; } </style> </head> <body> <h1>Prime Checker</h1> <p>Enter a positive number and click the button to check if it is prime or not.</p> <input type="number" id="number" min="1" value="1"> <button id="check">Check</button> <p id="result"></p> <script> // get the input element const number = document.getElementById("number"); // get the button element const check = document.getElementById("check"); // get the result element const result = document.getElementById("result"); // add a click event listener to the button check.addEventListener("click", function() { // get the input value let n = parseInt(number.value); // check if the input is valid if (isNaN(n) || n < 1) { // display an error message result.textContent = "Please enter a valid positive number."; } else { // call the function to check if the number is prime let isPrime = checkPrime(n); // display the result if (isPrime) { result.textContent = n + " is a prime number."; } else { result.textContent = n + " is not a prime number."; } } }); // function to check if a number is prime function checkPrime(n) { // check if the number is 1 if (n === 1) { // 1 is neither prime nor composite return false; } // check if the number is 2 if (n === 2) { // 2 is the only even prime number return true; } // check if the number is even if (n % 2 === 0) { // even numbers are not prime return false; } // loop from 3 to the square root of the number for (let i = 3; i <= Math.sqrt(n); i += 2) { // check if the number is divisible by any odd number if (n % i === 0) { // the number is not prime return false; } } // the number is prime return true; } </script> </body> </html>
Write, Run & Share HTML code online using OneCompiler's HTML online Code editor for free. It's one of the robust, feature-rich online Code editor for HTML language, running on the latest version HTML5. Getting started with the OneCompiler's HTML compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as HTML
. You can also specify the stylesheet information in styles.css
tab and scripts information in scripts.js
tab and start coding.
HTML(Hyper Text Markup language) is the standard markup language for Web pages, was created by Berners-Lee in the year 1991. Almost every web page over internet might be using HTML.
<!DOCTYPE html>
<html>
and ends with </html>
<h1>
to <h6>
where <h1>
is the highest important heading and <h6>
is the least important sub-heading.<p>..</p>
tag.<a>
tag.
<a href="https://onecompiler.com/html">HTML online compiler</a>
<img>
tag, where src
attribute consists of image name.<button>..</button>
tag<ul>
for unordered/bullet list and <ol>
for ordered/number list, and the list items are defined in <li>
.<a href="https://onecompiler.com/html">HTML online compiler</a>
CSS(cascading style sheets) describes how HTML elements will look on the web page like color, font-style, font-size, background color etc.
Below is a sample style sheet which displays heading in green and in Candara font with padding space of 25px.
body{
padding: 25px;
}
.title {
color: #228B22;
font-family: Candara;
}
<table>
tag.<tr>
tag<th>
tag<td>
tag<caption>
tag<script>
is the tag used to write scripts in HTML<script src="script.js"></script>