javascriptpromptcoderunner

"prompt is not defined"


I am trying to create a simple geometry program in JavaScript, but for some reason when I try to run the code in a code runner, it says

Error: prompt is not defined.

Note: I am using a code running app called Code Runner on my Mac.

var question = prompt("What do you want to know?")
if (question = "circumference of circle") {
  var variableCircumferenceCircle = prompt("What is the radius of the circle?")
  return variableCircumferenceCircle
  circumferenceCircle(variableCircumferenceCircle)
}

//Circumference of Circle:
var circumferenceCircle = function(r) {
  console.log("Circumference of Circle = 2 * pi * r")
  console.log("C = 2 * 3.14 * " + r)
  console.log("C = " + 2 * 3.14 * r)
}

Solution

  • window.prompt() only exists as a host function in the browser.

    Other than that environment, if you didn't create it, it will be undefined.