Program should keep looping to ask user for input on a to do list until they enter "quit" to exit. It works but only once as it does not loop as it should be. I need it to display the input as a list until "quit" is entered.
Can't figure out why
// global variables
var output;
function buildList(input) {
"use strict";
// declare variables
var unorderedList;
var inputList;
unorderedList = document.getElementById("toDo");
inputList = "<li>" + input + "</li>";
unorderedList.innerHTML = inputList;
}
function displayList() {
"use strict";
// PART 1: YOUR CODE STARTS AFTER THIS LINE
// declare constants
const QUIT_CODE = "quit";
// declare variables
var output;
var input;
while (input !== QUIT_CODE) {
input = prompt("Enter a to-do item or \"quit\" to stop: ");
output = document.getElementById("outputPart1");
buildList(input);
output.innerHTML += inputList;
if (input === QUIT_CODE) {
break;
}
}
// end of code
}
inputListis undefined in the context:output.innerHTML += inputList;because it was defined somewhere else.// global variablesyou barely ever need (or want) global variables. Certainly not in this code.