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
}
I made it a little simpler, also it works:
function buildList(input) {
"use strict";
var inputList;
inputList = "<li>" + input + "</li>";
document.getElementById("toDo").innerHTML += inputList;
}
function displayList() {
"use strict";
const QUIT_CODE = "quit";
var input;
while (input !== QUIT_CODE) {
input = prompt("Enter a to-do item or \"quit\" to stop: ");
if(input !== QUIT_CODE)
buildList(input);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With