I have a program that takes in parameters from a form and uses them to generate a narrative comment (meant for teachers that need to write narrative comments on grade reports):
const sentences = {
"participation": "engages productively in class discussions",
"assignments": "completes all assignments on time",
"mastery": "shows excellent understanding of the content on all assessments"
}
function writeComment(event) {
event.preventDefault();
let name = document.getElementById('name').value;
let schoolClass = document.getElementById('schoolClass').value;
let term = document.getElementById('term').value;
let strength1 = sentences[document.getElementById('strength1').value];
let strength2 = sentences[document.getElementById('strength2').value];
let result = `It has been wonderful having ${name} in ${schoolClass} during the ${term} term!
${name} ${strength1}. ${name} ${strength2}`
document.getElementById('result').innerText = result;
}
I'd like to store const sentences in a separate file, with other similar objects, that the current script would read from and use to populate the result. Is there a way to do that? I've tried storing it in a json file and using fetch on a local server but I wasn't able to actually make the data accessible to the script.