Template for assignments in js
This commit is contained in:
34
script.js
Normal file
34
script.js
Normal file
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user