The 3 Functions that make TACOCAT cool!
reverseString() {
//use the RegExp to remove unwanted characters from it
var re = /[\W_]/g;
//Get the user's word
let userWord = document.getElementById("tacoCat").value.toLowerCase()
//Sanatize the string
let cleanedWord = userWord.replace(re, '');
//Do something here with it
let start = cleanedWord.length - 1;
let reverseWord = "";
let palindrome = "";
stringLengthCheck(userWord.length);
for (let i = start; i >= 0; i--) {
reverseWord += cleanedWord[i];
}
palindrome = palindromeCheck(cleanedWord, reverseWord);
output = document.getElementById("tacoOutput");
output.innerText = "Your string reversed is: " + reverseWord;
output = document.getElementById("resultsOutput");
output.innerText = palindrome;
}
function palindromeCheck(origrnalString, reverseString) {
let palindromeCheckResult = "";
if (reverseString === origrnalString) {
palindromeCheckResult = "This is vaild palindrome. TacoCat owes you 2 tacos."
} else {
palindromeCheckResult = "This is Not vaild palindrome. Sorry no tacos for you."
}
return palindromeCheckResult;
}
function stringLengthCheck(orginalStringLen) {
if (orginalStringLen <= 2) {
//TODO add SweetAlert2
alert("Your String Needs to have at least 2 leters or numbners")
}
}