Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

251
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda