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

264
Vistas
js code working in console but not in vs code

I'm a beginner, learning js. I was doing a course and the task provided was that to pop an alert when the button is clicked. Pretty Ez but everytime somehow the code just doesn't works even when I typed the code seeing the solution. Checked pretty much everything within my knowledge but couldn't figure it out. while trying the same thing in another computer, it worked without any problem :/Here's the code

about 4 years ago · Santiago Gelvez
2 Respuestas
Responde la pregunta

0

Window.alert is not native JS. It is a Web API method, meaning your browser source code implements it.

If you're running, say, a Node.js environment in VSCode's console, then it shouldn't really work. Node doesn't implement it either.

about 4 years ago · Santiago Gelvez Denunciar

0

I have made an example here on a code pen: https://codesandbox.io/s/buttontoalert-fs1kz3

What you need to do is create an index.html that is importing the script you want to run.

<!DOCTYPE html>
<html>
  <head>
    <title>Parcel Sandbox</title>
    <meta charset="UTF-8" />
  </head>

  <body>
    <button>Click Me</button>

    <script src="src/index.js"></script>
  </body>
</html>

Then in your index.js file which is the script you are importing in the html file the code is:

const button = document.querySelector("button");

button.addEventListener("click", () => alert("I was clicked"));

These two file need to be in the same directory or you need to update the file path to where the js file is located relative to your html file.

The commands you are using a relative to a browser so need to be run with a browser or will not work.

about 4 years ago · Santiago Gelvez Denunciar
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