Why won't this function work?


#1

var name = prompt(“Tell me your name”)
function sayHello(name){
console.log(“Hello” + name);
}


#2

functions only execute when called. You never call the function


#3

How do I call it? If I put console.log(sayHello) underneath it still doesn’t print the message


#4

Now that you know what you are looking for, you can consult documentation:

https://developer.mozilla.org/nl/docs/Web/JavaScript/Guide/Functions


#5

So now i’ve got this:
var sayHello = function(){
var name = prompt(“Tell me your mf name you piece of crap!!!”);
console.log("Hello " + name + “!”);
}
console.log(sayHello());

It works fine on this other website i’m using, but if I type it in on the Codecademy type editor, it will say that “prompt is not defined at sayHello” which I don’t understand because prompt is a premade tool that the website already understands right?


#6

sounds like a glitch in the website, maybe refresh/reset the exercise? Or try a different browser altogether.


#7

Okay, thanks/ I looked it up and it seems like a lot of people started having that problem after the website updated.