Hello, My program isn\'t displaying the results. It should print all numbers ent
ID: 3712231 • Letter: H
Question
Hello,
My program isn't displaying the results. It should print all numbers entered that arent a duplicate and meet requirements of program.
comments and output appreciated
<!DOCTYPE html>
<html lang=en>
<head>
<meta charset="utf-8">
<title>Part 4</title>
</head>
<body>
Enter Number: <input type="text" id="input" value="">
<button>Submit</button>
<script>
function numEnter() {
document.getElementById("input").value = "";
}
</script>
<script>
var input = [];
var output = [];
for(var i = 0; i= 10 && input[i] <= 100 && !output.includes(input[i])) {
output.push(input[i]);
console.log(input[i]);
}}
else { console.log("Invalid number: " + input[i]);
}}
</script>
</body>
</html>
Thank you
Explanation / Answer
<!DOCTYPE html>
<html lang=en>
<head>
<meta charset="utf-8">
<title>Part 4</title>
</head>
<body>
Enter Number: <input type="text" id="input" value="">
<button>Submit</button>
<script>
var input = [];
var output = [];
function numEnter() {
var enteredValue = parseInt(document.getElementById("input").value);
if (isNaN(enteredValue)) {
document.getElementById("input").value = "";
console.log("Invalid number: " + enteredValue);
}
else{
input.push(enteredValue);
for (var i=0; i<input.length; i++)
{
// Check if the picked element is already printed
var j;
for (j=0; j<i; j++){
if (input[i] == input[j])
break;
}
// If not printed earlier, then print it
if (i == j)
console.log(input[i]);
}
document.getElementById("input").value = "";
}
}
</script>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.