From b754056efd80cfed377e5c6d4e5201f2f14d5364 Mon Sep 17 00:00:00 2001 From: paulusgaming Date: Sun, 4 Dec 2022 18:24:26 +0100 Subject: [PATCH] Template for assignments in js --- index.html | 16 ++++++++++++++++ script.js | 34 ++++++++++++++++++++++++++++++++++ style.css | 15 +++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 index.html create mode 100644 script.js create mode 100644 style.css diff --git a/index.html b/index.html new file mode 100644 index 0000000..5cf1ba4 --- /dev/null +++ b/index.html @@ -0,0 +1,16 @@ + + + + + + + + +

Assignment:

+ + +

Answer:

+
Provide input first
+ + + \ No newline at end of file diff --git a/script.js b/script.js new file mode 100644 index 0000000..e8d8ed8 --- /dev/null +++ b/script.js @@ -0,0 +1,34 @@ +const ASSIGNMENT = 'assignment'; +const ANSWER = 'answer'; +const NEWLINE_CHARACTER = '\n'; +const TOP_N = 3; + +/** + * Main function + */ +window.onload = function() { + document.getElementById(ASSIGNMENT).addEventListener("input", calculateAnswer); +} + +/** + * Listener function for input in assignment field. + * @param event the onInput event + */ +function calculateAnswer(event) { + console.info("Calculating answer for input..."); + let answer = algorithm(event.target.value, TOP_N); + + document.getElementById(ANSWER).innerText = answer; +} + +/** + * Calculate the answer to assignment. + * @param assignment the input from the assignment. + * @return string the answer + */ +function algorithm(assignment) { + let lines = assignment.trim().split(NEWLINE_CHARACTER); + console.info("Linecount:" + lines.length); + + // TODO: implement assignment +} \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..f39a6bd --- /dev/null +++ b/style.css @@ -0,0 +1,15 @@ +body { + background: transparent; /* Make it white if you need */ + color: #fc8224; + padding: 0 24px; + margin: 0; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; + } + + #answer { + color: purple + } + + p { + margin: 0px + } \ No newline at end of file