Skip to content

Commit 6596ef3

Browse files
committed
JS-prompt Issuse solved
Added details in readme file, deleted
1 parent 0b929bc commit 6596ef3

3 files changed

Lines changed: 17 additions & 58 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
11
# JavaScript-Practice
2+
23
This Contains Javascript Files
4+
5+
## Reason for not executing JS File, prompt command
6+
7+
- prompt() is a method of the Global window object found in browsers. It's not part of the JavaScript language.
8+
- window object is not defined in this environment.
9+
- Step 1: npm init
10+
Step 2: npm install prompt-sync
11+
Step 3: Open the js file (name.js) in which you want to use prompt and import the prompt-sync as given below. (on line 1)
12+
eg: const prompt = require("prompt-sync")();
13+
14+

index.html

Lines changed: 0 additions & 56 deletions
This file was deleted.

projects/1.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
// if else
44
// result display console.log
55

6+
const prompt = require("prompt-sync")(); //This is required for prompt to work
7+
68
const operator = prompt('Enter Operator (either +,-,*,/):');
79

810
const num1 = parseFloat(prompt('enter 1st number:'));
9-
const num2 = parseFloat(prompt('enter 2nd number:'));
11+
const num2 = parseFloat(prompt('enter 2nd number:'));
1012

1113
let result;
1214
// conditions
@@ -27,4 +29,5 @@ else if(operator == '/') {
2729
}
2830
console.log(num1, operator, num2, '=', result);
2931

30-
// Still facing problem in executing JS Files, Fix this Issue
32+
// Still facing problem in executing JS Files, Fix this Issue
33+
// ** Issue solved, using const prompt = require("prompt-sync")(); at the top

0 commit comments

Comments
 (0)