heliu heliu - 5 months ago 16
Javascript Question

How can I make a function that takes in a parameter and when executed, it alerts whatever you give the function?

I am in a coding bootcamp prep class and I did not pass my first quiz because i did not understand functions. I talked to my mentor about the problem that get me stuck, he said it does not remember the problem word by word but it was

"It is basically writing a function that takes a parameter and when executed it alerts whatever you give the function"

I guess what got me stuck was when I writing the function when I got to the part

var varName = function(parameter){ alert()}

I was not too sure what to put in the
, I keep thinking it was supposed to take in a string so when it actually alerts, it will display something a sentence to tell the user.

var varName = function(parameter){ alert(parameter)}

Thats the slight edit from your attempt. Rest is fine.

call it like varName("Hello World")


var varName = function(parameter) {
varName("Hello World");

Have a look at the MDN Docs for alert() or at SO Socumentation example here .