Files
advent-of-code/script.js

33 lines
820 B
JavaScript
Raw Permalink Normal View History

2022-12-04 18:24:26 +01:00
const ASSIGNMENT = 'assignment';
const ANSWER = 'answer';
const NEWLINE_CHARACTER = '\n';
/**
* 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...");
2022-12-04 18:39:25 +01:00
let answer = algorithm(event.target.value);
2022-12-04 18:24:26 +01:00
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
}