From 6c9af4e8f9af839b632493c2c975eb456d3dc5e6 Mon Sep 17 00:00:00 2001 From: Nur Amirah Sham Date: Tue, 16 Jun 2020 00:25:35 +0800 Subject: [PATCH 1/2] added script for draw this program --- index.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/index.html b/index.html index 77832ae..0a6a00c 100644 --- a/index.html +++ b/index.html @@ -12,8 +12,7 @@

output:

var currentInput = event.target.value; inputHappened(currentInput) }); - - + \ No newline at end of file From 20717c6bfbc5d867e203abae2fd409ed7b0be75f Mon Sep 17 00:00:00 2001 From: Nur Amirah Sham Date: Tue, 16 Jun 2020 00:25:54 +0800 Subject: [PATCH 2/2] added script for draw this program --- script.js | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/script.js b/script.js index 6582e0d..bc9fa16 100644 --- a/script.js +++ b/script.js @@ -1,11 +1,48 @@ console.log("hello script js"); +document.getElementById("output").innerText = "Draw with emoji" +//variables and functions +var emoji = ""; + +function clearElements() { + document.querySelector("#input").value = ""; + document.getElementById("output").innerText = ""; +} + +function splitInput(x) { + var array = x.split(" "); + return array; +} + +//DOM Manipulation code goes here var inputHappened = function(currentInput){ - console.log( currentInput ); - display( "WOW SOMETHING HAPPENED" ); -}; + + var array = splitInput(currentInput); + var arrayNumber = parseInt(array[1]); + + if (array.length === 1 && array[0] === "clear") { + clearElements(); + } else if (array[0] === "clear" && array.length > 1) { + document.getElementById("output").splice(arrayNumber, 1); + } else if (typeof(array[0]) !== 'number' && typeof(array[1])!== 'number') { + for (var i = 0; i < arrayNumber; i++) { + display(array[0]); + } + } else { + display(currentInput); + } +} var display = function(stuffToDisplay){ - // your DOM manipulation code here - -}; + var pTag = document.createElement('p'); + + for (var i = 0; i < stuffToDisplay; i++) { + emoji += "🗿"; + } + + pTag.classList.add("emoji"); + pTag.textContent = emoji; + + var output = document.getElementById("output"); + output.appendChild(pTag); + }; \ No newline at end of file