0

Mysupername is the value that got printed out and not the expected output.

I already tried reinstalling it. I used npm install prompt -sync to use it with JavaScript inside Visual Studio Code but I don't know where I am going wrong. I have already added the variables in system advanced setting.

Visual Studio Code error message if I try to use prompt or alert inside and run through code runner extension:

Ammad Ali
  • 19
  • 7

1 Answers1

1

There's a slight mistake with your code. Firstly, the reason why it is printing Mysupername to the console is because you provided console.log with a string. Instead just provide the variable name like this:

const superheroes = require('superheroes');

var Mysupername = superheroes.random();

console.log(Mysupername);

Now, the reason why prompt isn't working is because you never imported the library into your code, you can do it by the following:

const prompt = require("prompt");

Final note, alert is only available when running javascript through a browser.

Nabeel Ahmed
  • 146
  • 1
  • 4
  • 1
    That does solve the problem. Thank you very much for your help and time. I am new and still learning but I'll work harder next time. – Ammad Ali Jul 23 '22 at 19:45