Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

247
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda