The idea for now is to just display "hello world!" to check if the function is being called properly by the button. I've tried to copy-paste from previous code that worked, checked the parentheses, brackets, anything that could disrupt the function call. While nothing after the "hello world!" is necessary to answer the question, I'd greatly appreciate it if you gave suggestions for the rest of the code below. The idea there is to take user input, and give different results based on string length.
function persona() {
document.write("hello world!");
var name, inputstr, sum = 0;
name = document.getElementById("input").value;
inputstr = name.length;
while (inputstr / 10 >= 1) {
if (inputstr = 11 || inputstr = 22) {
break;
}
sum += inputstr % 10;
inputstr = Math.floor(inputstr / 10);
if (inputstr = 11 || inputstr = 22) {
break;
}
}
switch (inputstr) {
case 1:
document.getElementById("results").innerHTML = "...";
break;;
case 2:
document.getElementById("results").innerHTML = "...";
break;;
case 3:
document.getElementById("results").innerHTML = "...";
break;;
case 4:
document.getElementById("results").innerHTML = "...";
break;;
case 5:
document.getElementById("results").innerHTML = "...";
break;;
case 6:
document.getElementById("results").innerHTML = "...";
break;;
case 7:
document.getElementById("results").innerHTML = "...";
break;;
case 8:
document.getElementById("results").innerHTML = "...";
break;;
case 9:
document.getElementById("results").innerHTML = "...";
break;;
case 11:
document.getElementById("results").innerHTML = "...";
break;;
case 22:
document.getElementById("results").innerHTML = "...";
break;;
}
}
body {
background-color: #a89b28;
color: #f0f1f6;
font-family: impact;
text-align: center;
}
<!DOCTYPE html>
<html>
<title>Number Personality Calculator</title>
<head>
<meta name="description" content="Input your name, and predict your personality type" />
<meta name="keywords" content="JavaScript, JS, numerology, personality" />
<meta name="author" content="[REDACTED], 18/02/2018" />
<meta charset="UTF-8">
</head>
<body>
<h1>PERSONALITY TYPE CHECKER</h1>
<p id="results">""</p>
<input type="text" id="input" placeholder="Juan Dela Cruz"><br>
<button onclick="persona()">Get your personality</button>
</body>
</html>
document.writeafter the page has been parsed (or maybe at all).dwclears the page and creates a new document.element.addEventListener.alert()insteadinnerHTMLattribute. You can do this like:let resultsElement = document.getElementById("results"); resultsElement.innerHTML = "Hello World.";