Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

243
Views
How to put data currently in a const object within the script in a separate file?

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!