The Code for UFO Tofu

                     

// Validation on user input
function isValid() {
	// Get Values from Page
	let usrInput = document.getElementById('usrInput').value;

	// Validates input (makes sure input is not empty)
	if (usrInput === '') {
		alert('Please enter a word or phrase');
	} else {
		emptyOutput();
		printOuput(usrInput, modify(usrInput), reversify(modify(usrInput)));
	}
}

// Empty the results on the page
function emptyOutput() {
	let output = document.getElementById('results');
	output.innerHTML = '***Results Go Here***';
}

// This function takes out punctuation and changes everything to lowercase
function modify(str) {
	let modStr = '';

	for (let i = 0; i < str.length; i++) {
		if (/[a-zA-Z0-9]/.test(str[i])) {
			// tests if the string is alphanumeric
			modStr += str[i].toLowerCase();
		}
	}
	return modStr;
}

// This function reverses the passed string
function reversify(str) {
	let revStr = '';

	for (let i = str.length - 1; i >= 0; i--) {
		revStr += str[i];
	}
	return revStr;
}

// This function gived the appropriate output if it is or isn't a palindrome
function printOuput(usrInput, modified, reversed) {
	if (modified === reversed) {
		document.getElementById('results').innerHTML = `

${usrInput} is absolutely a Palindrome

${modified} is the same as ${reversed}!

`; } else { document.getElementById( 'results' ).innerHTML = `

${usrInput} is not a Palindrome

${modified} and ${reversed} don't appear to be the same.

`; } }

The Code is structured in the following functions

isValid

isValid is a function that checks first if the user input is not empty. If it isn't, it will alert the user to enter a valid entry. If it is valid, it will then empty the previous results and send the input to be printed by calling three functions modify, reversify, and printOutput

emptyOutput

emptyOutput removes anything previous in the results area.

modify

modify takes the user valid user input and goes through each letter and stores it in a new string after checking if it is alphanumeric and makes it lowercase for ease of comparison. It then return the modified string.

reversify

reversify takes the newly modifed string and returns the exact string reversed

printOutput

printOutput takes the original user input, the modified input, and the reversed version of the input and displays a message signifying if the input is or is not a palindrome.