Random name picker with Javascript

My wife and I will become parents. I believe most of the future parents have the same issue, we cannot agree about the name for our little son. 🙂 After a few days (weeks) we have made a long list of all the names we but some names that are in my short circuit are not even close to her 🙂 In the absence of idea I decided to make a name generator with JavaScript that will help us choose the name 🙂 Sweet ha?
Below is a whole code that I wrote, maybe will be useful to somebody.

Here is HTML

<h1 id="headerNames">?</h1>
<div class="button" id="startButton">start</div>
<div class="button" id="stopButton">stop</div>

Here is CSS

body {
	background: #333;
}

h1#headerNames {
	margin-top: 10%;
	color: #fff;
	font-family: Georgia, serif;
	font-size: 150px;
	text-align: center;
	cursor: pointer;
}

.button {
	width: 150px;
	margin: auto;
	padding: 20px;
	background: #1fa91f;
	border: 3px solid #fff;
	border-radius: 10px;
	color: #fff;
	font-family: Arial, sans-serif;
	font-size: 30px;
	font-weight: bold;
	text-align: center;
	text-transform: uppercase;
	letter-spacing: 2px;
	display: block;
	cursor: pointer;
}

#stopButton {
	background: #ff0000;
	display: none;
}

#timerWrapper {
	margin: 50px 0;
	color: #fff;
	font-family: Arial, sans-serif;
	font-size: 50px;
	text-align: center;
	opacity: 0;
	transition: opacity 1s;
}
#timerWrapper.visible {
	opacity: 1;
}

Here is Javascript

"use strict";
const showTimer = true;
// Add list of names here
const namesList = [
	'Ivano',
	'Lovro',
	'Dominik', 
	'Vid',
	'Roko',
	'Luka',
	'Niko'
];

// Default variables
let i = 0;
let x = 0;
let intervalHandle = null;
const startButton = document.getElementById('startButton');
const stopButton = document.getElementById('stopButton');
const headerOne = document.getElementById('headerNames');

// Optional countdown timer
// Add zero in front of numbers < 10
function checkSecond(sec) {
  if (sec < 10 && sec >= 0) {
		sec = "0" + sec;
	} 
  if (sec < 0) {
		sec = "59";
	}
  return sec;
}
// Start or stop the name shuffle on the button click
startButton.addEventListener('click', function() {
	this.style.display = "none";
	stopButton.style.display = "block";
	intervalHandle = setInterval(function () {
		headerNames.textContent = namesList[i++ % namesList.length];
	}, 50);
	if (showTimer===true) {
		timerWrapper.classList.remove('visible');
	}
});
stopButton.addEventListener('click', function() {
	this.style.display = "none";
	startButton.style.display = "block";
	clearInterval(intervalHandle);
	timer.innerHTML = time;
	if (showTimer===true) {
		timerWrapper.classList.add('visible');
	}
	startTimer();
});

// Allow use of spacebar to start/stop name shuffle
document.body.onkeyup = function(e) {
	if (e.keyCode == 32) {
		if (x%2===0) {
			startButton.style.display = "none";
			stopButton.style.display = "block";
			intervalHandle = setInterval(function () {
				headerNames.textContent = namesList[i++ % namesList.length];
			}, 50);
			if (showTimer===true) {
				timerWrapper.classList.remove('visible');
			}
		} else {
			startButton.style.display = "block";
			stopButton.style.display = "none";
			clearInterval(intervalHandle);
			timer.innerHTML = time;
			if (showTimer===true) {
				timerWrapper.classList.add('visible');
			}
			startTimer();
		}
		x++; 
	}
}

Demo is here.

You can also read this

How to block F12 key with jQuery

In this post, I will show you how to disable...

$(document).on("contextmenu",function(e){        
   e.preventDefault();
});

Croatia recession prediction

This LSTM recurrent neural network learns to predict Croatia economic...

pred.train_LSTM()
pred.evaluate_LSTM()
pred.display_results(