Created
September 9, 2025 16:38
-
-
Save susanBuck/bd12cffbb91c7cbb4701fce7bdb1b115 to your computer and use it in GitHub Desktop.
Note on capturing responses with the prompt method and reusing variables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Don’t redeclare the same variable: | |
| let answer = prompt('What is 1 + 1?'); | |
| console.log('You answered: ' + answer); | |
| let answer = prompt('What is 4 + 8?'); | |
| console.log('You answered: ' + answer); | |
| // Instead do this: | |
| let answer = prompt('What is 1 + 1?'); | |
| console.log('You answered: ' + answer1); | |
| answer = prompt('What is 4 + 8?'); // second reference does not use "let" | |
| console.log('You answered: ' + answer); | |
| // Or declare a separate variable: | |
| let answer1 = prompt('What is 1 + 1?'); | |
| console.log('You answered: ' + answer1); | |
| let answer2 = prompt('What is 4 + 8?'); | |
| console.log('You answered: ' + answer2); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment