Commit eeaa8def authored by Ratnadeep Rajendra Kharade's avatar Ratnadeep Rajendra Kharade
Browse files

added comments for improved readability

parent 4ddfbc5f
// Object which stores all the user selected/entered values
let inputObj = { let inputObj = {
textChoice: 'manual', textChoice: 'manual', // choice of text entry initially set as manual. Can have values manual, calculated
text: '', text: '', // User entered text in case of manual
textLength: '', textLength: '', // number of characters in text. Either from user enetered text or user entered number
readerLevel: '', readerLevel: '', // Value of reader level selected from dropdown
readerCategory: '' readerCategory: '' // Value of reader category selected from dropdown
}; };
// function handleTextRadioClick: responsible for showing or hiding text input / text length input based on selected option
function handleTextRadioClick() { function handleTextRadioClick() {
let textChoice = document.querySelector('input[name="text-input-option"]:checked').value; let textChoice = document.querySelector('input[name="text-input-option"]:checked').value;
console.log(textChoice);
inputObj.textChoice = textChoice; inputObj.textChoice = textChoice;
toggleElement('character-calculation-wrapper'); toggleElement('character-calculation-wrapper');
toggleElement('manual-character-input'); toggleElement('manual-character-input');
} }
// function toggleElement: hides/shows the html element based on current visibility.
// accepts value of id attribute of element as parameter
function toggleElement(id) { function toggleElement(id) {
let x = document.getElementById(id); let element = document.getElementById(id);
if (x.style.display === "none") { if (element.style.display === "none") {
x.style.display = "block"; element.style.display = "block";
} else { } else {
x.style.display = "none"; element.style.display = "none";
} }
} }
// function handleTextAreaChange: captures the changes as user enters the text and gets the length
// and sets number of characters to property textLength on inputObj
function handleTextAreaChange() { function handleTextAreaChange() {
let value = document.getElementById("manual-text-entry").value; let value = document.getElementById("manual-text-entry").value;
value = value.trim(); value = value.trim();
...@@ -32,23 +40,23 @@ function handleTextAreaChange() { ...@@ -32,23 +40,23 @@ function handleTextAreaChange() {
document.getElementById("calculatedTextCharacters").setAttribute('value', characters) document.getElementById("calculatedTextCharacters").setAttribute('value', characters)
} }
// function handleCharacterInputChange: captures changes in number of characters input field
// and sets number of characters to property textLength on inputObj
function handleCharacterInputChange() { function handleCharacterInputChange() {
let value = document.getElementById("inputTextCharacters").value; let value = document.getElementById("inputTextCharacters").value;
setCharacterLength(value); setCharacterLength(value);
} }
// function setCharacterLength: sets number of characters to property textLength on inputObj
function setCharacterLength(characters) { function setCharacterLength(characters) {
inputObj.textLength = characters; inputObj.textLength = parseInt(characters);
console.log('Character length: ' + inputObj.textLength);
} }
function calculateReadingTime() {
if (isFormValid()) {
let x = document.getElementById('calculate-time-element');
x.style.display = "block";
}
}
// function isFormValid: checks for mandatory input fields and validates te form
// returns true if all values are filled else returns false
// also shows error messages for respective inputs fields
function isFormValid() { function isFormValid() {
let invalidFields = 0; let invalidFields = 0;
if (inputObj.textChoice === 'manual' && inputObj.text === '') { if (inputObj.textChoice === 'manual' && inputObj.text === '') {
...@@ -80,20 +88,47 @@ function isFormValid() { ...@@ -80,20 +88,47 @@ function isFormValid() {
} }
return invalidFields < 1 return invalidFields < 1
} }
// function showFeedbackForm: displays feedback form when calculation is done
function showFeedbackForm() { function showFeedbackForm() {
let x = document.getElementById('feedback-form'); let element = document.getElementById('feedback-form');
x.style.display = "block"; element.style.display = "block";
} }
// function readerLevelChangeEvent: listens for change in reader level dropdown
// and sets selected value to property readerLevel on inputObj
function readerLevelChangeEvent(event) { function readerLevelChangeEvent(event) {
console.log(event.target.value)
inputObj.readerLevel = event.target.value; inputObj.readerLevel = event.target.value;
} }
// function readerCategoryChangeEvent: listens for change in reader category dropdown
// and sets selected value to property readerCategory on inputObj
function readerCategoryChangeEvent(event) { function readerCategoryChangeEvent(event) {
console.log(event.target.value)
inputObj.readerCategory = event.target.value; inputObj.readerCategory = event.target.value;
} }
// function calculateReadingTime: This function is responsible for calculating reading time
// reading time can be calculated if all inputs are valid
function calculateReadingTime() {
if (isFormValid()) {
//variable x which holds final reading time in minutes
let x = 0;
console.log(inputObj);
// TODO: logic or algorithm for calulating reading time goes here
// inputObj.textLength has number of characters (number data type)
// inputObj.readerLevel has level of reader (string data type)
// inputObj.readerCategory has category of reader (string data type)
// display html element which shows time
let element = document.getElementById('calculate-time-element');
element.style.display = "block";
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment