Skip to content

Instantly share code, notes, and snippets.

@susanBuck
Created September 9, 2025 16:38
Show Gist options
  • Select an option

  • Save susanBuck/bd12cffbb91c7cbb4701fce7bdb1b115 to your computer and use it in GitHub Desktop.

Select an option

Save susanBuck/bd12cffbb91c7cbb4701fce7bdb1b115 to your computer and use it in GitHub Desktop.
Note on capturing responses with the prompt method and reusing variables
// 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