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

366
Visualizações
Uncaught ReferenceError: revealMessage is not defined

I was setting up a basic website, but for some reason when I went to test it I was confused to find that it wasn't quite working like usual. I keep getting this error. "Uncaught ReferenceError: revealMessage is not defined"

<!DOCTYPE html>
<html>
    <head>
        <script src="js/script.js"></script>
        <title>Rock Paper Scissors!</title>
    </head>
    <body>
        <button onclick="revealMessage()">Click!</button>
        <p id="hiddenMessage" style="display:none">hidden message thingy</p>
    </body>
</html>

function revealMessage() {
    document.getElementById("hiddenMessage").style.display = "block";
}

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

The only thing I can see that could be a possible issue is if your JavaScript file is not within a folder named "js". You said that your js is in another folder; if it is named anything other than "js", then your html file is trying to access the JS file within a folder that does not exist. So your file structure should look like

- [html file name].html
- js/
    - script.js
about 4 years ago · Juan Pablo Isaza Relatório

0

Your two snippets were disconnected. Just put HTML and JS code into same snippet and it should work. See below:

function revealMessage() {
    document.getElementById("hiddenMessage").style.display = "block";
}
<!DOCTYPE html>
<html>
    <head>
        <script src="js/script.js"></script>
        <title>Rock Paper Scissors!</title>
    </head>
    <body>
        <button onclick="revealMessage()">Click!</button>
        <p id="hiddenMessage" style="display:none">hidden message thingy</p>
    </body>
</html>

about 4 years ago · Juan Pablo Isaza Relatório

0

Looks like there is no problem with the code but just check if your function is in global scope or local scope.

Also make sure that your js file is linked to your html properly. Check your js file with a basic alert();

about 4 years ago · Juan Pablo Isaza Relatório
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