function problem

0 Diego Mc · September 15, 2015
I wrote this code and it seems all correct but for some reason, it doesn't execute.
it's not showing any error messages but it's just not running, not the function neither the prompt.
does anyone have any idea why?

Post a Reply


Oldest  Newest  Rating
+2 Donald Trump · September 15, 2015
you probably just made it and never called it. call it in the body like so:

<body onLoad="greet();">
    // html content
+2 Casper Hollemans · September 16, 2015
Well my first question is why do you give the feel var a type of int, i assume it will be a string right?

also for the var name and last name it will think hey i need a number over here and get a string, normally you'd get a error i think but maybe i'm wrong.

but try this:
function greet(n, l){
feel = prompt('bla.....')

name = prompt('');
// same for lastname

greet(name, lastname)

I also saw somthing else you did use the same var's in your parameters for the func as outside the func, this can't be done or well that's not true but for now i wouldn't try it's a bit more advanced.
I did correct that to in the code try it and let me hear if it works :)

0 Diego Mc · September 17, 2015
I thought that simply writing the name of the func with (); at the end of it will call it.
0 Diego Mc · September 17, 2015
Casper. it works great' thank you very much:)
0 Diego Mc · September 17, 2015
Milan, I didn't knew you could call a function from inside the body tag, thank you for teaching me that:)
+1 Casper Hollemans · September 17, 2015
So it was the wrong declaration of the variable?
+1 Casper Hollemans · September 17, 2015
btw if we look to your function:

Function greet(name, lastname){


we see that it takes/needs 2 parameters, if you call the function and leave the parameters blank it won't work.
It'll think "hey I need 2 things but i can't see them so i coul'd better not run before i mess somthing up" (yes this is how a function thinks in real life xD)
so if you declare a function with params always call it and give it value then:

greet("casper", "Hollemans");
//or use variables like u did
greet("Fnmae", "Lname");

keep in mind do not double the variables like i told you before :)

+1 Diego Mc · September 18, 2015
thanks for the help, you're awesome :)
+1 Casper Hollemans · September 18, 2015
haha thanks, it's no problem i bin a newbie to. :p
  • 1



A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.