Javascript/Why wont this code work, please help

+1 Robert Summers · June 4, 2015

// Below is the greeting function!
// See line 7
// We can join strings together using the plus sign (+)
// See the hint for more details about how this works.

var greeting = function sayHello('Robert') {
    console.log("Great to see you," + " " + name);
};

// On line 11, call the greeting function!
sayHello();

Someone tell me what I'm doing wrong? Thanks!

Post a Reply

Replies

Oldest  Newest  Rating
0 Oussama Fahchouch · June 10, 2015
It's the parameter.

function sayHello(name){
 console.log('Hello ' + name);
}

sayHello('Robert');

Watch some tutorials about functions and parameters :)!
0 Robert Summers · June 8, 2015
Thank you for your help. :)
0 Kirill Lukenyuk · June 7, 2015
just type like this.
it works
<script type="text/javascript">

var name;
function sayHello(name) {
console.log("Great to see you," + " " + name);
}
// On line 11, call the greeting function!
sayHello("Robert");


</script>
0 Robert Summers · June 5, 2015
I'm learning on code academy and here are some instructions

Function syntax
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.

?
Hint
When we want to join together two strings, we put a plus sign.
console.log("Hey" + "you");

will print out 
Heyyou

. That's not what we want!
If you want a space between words, you must add that space as well!
console.log("Hey" + " " +"you");

 will print out 
Hey you

This joining of strings is calledconcatenation
0 jordan de geus · June 5, 2015
What is your method for "sayHello()"?

I'm not sure what this code is/where its from, but if you could provide that, it'd be pretty helpful. 

To me it looks like theres a problem with the sayHello() object
  • 1

Javascript

107,044 followers
About

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

Links
Moderators