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?
/images/forum/upload/2015-09-14/79d45352e597591d9644ae35abb2ab8d.PNG

Post a Reply

Replies

Oldest  Newest  Rating
+1 Casper Hollemans · September 18, 2015
haha thanks, it's no problem i bin a newbie to. :p
+1 Diego Mc · September 18, 2015
thanks for the help, you're awesome :)
+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 :)

-Greets
+1 Casper Hollemans · September 17, 2015
So it was the wrong declaration of the variable?
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:)
0 Diego Mc · September 17, 2015
Casper. it works great' thank you very much:)
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.
+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){
alert('bla...');
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 :)

-Greets
+2 Milan Obrenovic · September 15, 2015
you probably just made it and never called it. call it in the body like so:

...
<body onLoad="greet();">
    // html content
</body>
...
  • 1

Javascript

107,185 followers
About

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

Links
Moderators