I do not understand how to call a function what am I doing wrong?


#1



Function Syntax

// On line 11, call the greeting function!
var sayHello ("Jamilia"){ console.log ("Hello + Jamilia);}

Replace this line with your code.


#7

The code in a function is not executed when the function is defined. It is executed when the function is invoked.
Some people use the term "call a function" instead of "invoke a function".
example 1:

function number(a, b) {
return a * b;
}
number(10, 2); // Calling the function

number(10,2) means first value(10) will go to first argument(a) and second one(2) to second(b)

To call a function, you simply need to pass the required parameters along with the function name, and if the function returns a value, then you can store the returned value.

example2:

var hello = function() {
console.log("i am saying hello");
};
hello();//Calling the function

example3

function hello(thing) {
console.log("Hello " + thing);
}
hello("world")//calling a function

why function?
You can reuse code: Define the code once, and use it many times.
You can use the same code many times with different arguments.
run this roo

function hello(thing) {
console.log("Hello " + thing);
}
hello("world")//calling a function
hello("sun")//calling a function
hello("moon")//calling a function

Define the code once, and use it many times

@masika37


Tying it all together
8. What if choice1 is scissors?
8.What if choice1 is "scissors".Please HELP!
How does a function work?
What if choice1 is paper?
Step four: Good afternoon codemen. Please tell me what is wrong with my code. Thankyou
5. Both choices are the same
Codecademy says: You did not call the greeting function. Pass it a name!
Function Review
# 3 Function Syntax lesson
Im stuck on the rock paper scissors
#8

@rcodeman Your explanation is clear and helpful, but I have a question about the "function call" section of your answer: Would you be passing "parameters" or "arguments"? Sometimes this can get confusing so I want to confirm I have it down right.


#9

functionName(parameter1, parameter2, parameter3) {
code to be executed
}

Function parameters are the names listed in the function definition.Function arguments are the real values passed to (and received by) the function.

@msfrisby


#10

Thanks, @rcodeman. So I'm passing the arguments to the space reserved by the parameters, is that right?

functionName (parameter) {
    (code)
}

functionCall(argument);

#11

yes :slight_smile:
think simple
parameters=names listed in the function
arguments= real values

@msfrisby


#12

var greeting = function (name) {
console.log("Great to see you," + name);
};
greeting("akhil")
look the codes been typed there.here in the variable name called "greeting" i define a function as function(name) which tells us that the variable "greeting " is now a function and going inside a function there is new as +name that is parameter which is also called the formal parameter. here we call the function "greeting" assigning value akhil which passes to parameter and which will printed via log of console of that statement.


#13

var sayHello=function (name){};

I am having a hard time understanding still can someone please tell me what am I doing wrong?!


#14

function example:

var hello = function() {
console.log("i am saying hello");
};
hello();//Calling the function

and its your function:

var sayHello=function (name){
// code to be executed here
};
// call the function here

@masika37


#15

Be sure this text matches exactly what is given in the instructions.


#16

var sayHello=function(){};


#17

var sayHello=function (name){console.log("Hello + There)};
sayHello();


#18

Please post a link to the exercise. Thank you.


#19

Introduction to Function Syntax 3.

A function takes in inputs, does something with them, and produces an output.

Here's an example of a function:

var sayHello = function(name) {
console.log('Hello ' + name);
};
First we declare a function using var, and then give it a name sayHello. The name should begin with a lowercase letter and the convention is to use lowerCamelCase where each word (except the first) begins with a capital letter.
Then we use the function keyword to tell the computer that you are making a function
The code in the parentheses is called a parameter. It's a placeholder word that we give a specific value when we call the function. Click "Stuck? Get a hint!" for more.
Then write your block of reusable code between { }. Every line of code in this block must end with a ;.
You can run this code by "calling" the function, like this:

sayHello("Emily");
Calling this function will print out Hello Emily.

Instructions
On line 11, call the greeting function and put in a name that you want the greeting function to include.
Press "Save & Submit Code" and see the function get into action! Saves you so much time.
?


#20

The first thing to do if this is not letting you pass is Reset. Change nothing in the provided code, and only do as instructed.

greeting("Wee Gillis");    // Great to see you, Wee Gillis

#21

yeah i miss one + there..... begged my mistake ....


#22

Really can not wait for this semester to be over! Then I can focus on phase one and getting into the immersive program. Thanks for all of your help much appreciated.


#23

so are you saying that to call a function greeting all I have to do is put
greeting("Hello");


#24

I am so frustrated I am not getting this!!!! I am following the instructions to best of my ability and Im still getting error messages now its saying I forgot to call the function now pass it a name. Can someone please help me


#25

Thank you very much Rcodeman. it has worked at last. Good day.