Skip to content

Instantly share code, notes, and snippets.

@voidnerd
Created September 13, 2018 11:21
Show Gist options
  • Save voidnerd/0b4761f4f62051dafc5ad352c444b65a to your computer and use it in GitHub Desktop.
Save voidnerd/0b4761f4f62051dafc5ad352c444b65a to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div title="ok" id="oked"></div>
<input type="text" id='ok' >
<script>
function generateList() {
let list = "<ul>";
for(i =0; i < foods.length; i++) {
list += "<li>" + foods[i] + "</li>";
console.log(list)
}
list += "</ul>";
return list;
}
//
var div = document.querySelector('#oked');
var input = document.querySelector('#ok');
let foods = ['rice', 'beans', "garri"];
let list = generateList();
div.innerHTML = list;
input.addEventListener('keydown', function(e) {
if(e.key == 'Enter') {
div.innerHTML = "";
foods.push(input.value);
list = "";
list = generateList();
div.innerHTML = list;
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment