JSFiddle - React, Tailwind, and code Playground

by Roman Zharikov

HTML

<input type="text" id="input" placeholder="">
<button>Узнать</button>
<h1>Результат</h1>

CSS

h1 {
  padding: 10px;
  border: 1px solid #ccc;
  text-align: center;
}

JavaScript

// hexlet course  =>   Введение в программирование
// author         =>   Roman Zharikov (zharikov.site)

//document.addEventListener("DOMContentLoaded", function() {

// define function
const isPrime = (num) => {
  if (num >= 0) {
    switch (num) {
      case 0:
      case 1:
        return false;
      case 2:
        return true;
      default:
        for (let i = 2; i < num; i++) {
          if (num % i === 0)
            return false;
        }
        return true;
    }
  } else {
    return false;
  }
}

var button = document.getElementsByTagName('button')[0],
  out = document.getElementsByTagName('h1')[0],
  input = document.getElementById('input');

button.addEventListener('click', function() {

  // call function and out result to DOM element
  out.innerHTML = (isPrime(parseInt(input.value))) ? 'Число простое' : 'Число не является простым';
});

//});