Tying it all togheter


#1

OK, GUYS, I'M GETTING COMPLETELY NUTS WITH THIS TOPIC !! CAN SOMEONE HELP ?

// Badly written function with syntax errors!

greeting var func{name}(console.log(name)))}
var greeting = function(greeting) {
var name = "Bessie";
console.log(Bessie);
};

SyntaxError: Unexpected token var


#2

greeting var func{name}(console.log(name)))}

Get rid of that line entirely.

var greeting = function(greeting) {
                            ^
 var name = "Bessie"; //<--Remove entire line.

 console.log(Bessie);
                ^
};

Alright so functions run off of parameters, essentially what a parameter is, is a holding point, a place that can be substituted for something else when needed. In the case the thing in the parameters function(greeting) is supposed to be a parameter, (Never use the name of an existing variable as a parameter).

var greeting = function( name ) {
                           ^

Secondly, remember that console.log statements can run off strings or variables, however this:

console.log(Bessie);

will not work. The variable "Bessie" was never defined, and if you wanted to make it a string you would need to put quotation marks around it, instead let's change it to accept the parameter, this way no matter what you put in the function it'll say that.

console.log(name);

So all together it would look like this:

var greeting = function(name) { 
    console.log(name);
};

Then in order to call your function and give it a parameter of whatever you want (let's use "Bessie") you'll need to do this:

greeting("Bessie");

This will change every "name" in your greeting function to "Bessie" Essentially the console would see this. (DON'T COPY THIS, Just an example!):

greeting( "Bessie" );

var breeting = function( "Bessie" ) {
    console.log( "Bessie" );
};

#3

Hello, There's someone working on Sunday, I guess .. like me. Your tips were amazing, but it didn't work, incredibly. And I've copied like you tauch:

greeting var func{name}(console.log(name)))}
var greeting = function(name) {
console.log(name);
};

Q&A ForumGlossary
script.js

1
2
3
4
5
6
7
8
9
10
11
12
13
// Nicely written function:
var calculate = function (number) {
var val = number * 10;
console.log(val);
};
// Badly written function with syntax errors!
greeting var func{name}(console.log(name)))}
var greeting = function(name) {
console.log(name);
};
SyntaxError: Unexpected token var

Save & Submit Code
Reset Code
Oops, try again. There was a problem with your syntax.


#4

hum hum. Thank you, my friend. But it wasn't that time, again !

var greeting = function(name) {
console.log("Yes, you did it " + " " + name);
};
greeting("Olá");

SyntaxError: Unexpected token var

Save & Submit Code
Reset Code
Oops, try again. There was a problem with your syntax.


#5

Hello, my dearrr.. but I'M STUCK in that lesson,for 2 days, at least, however your explanations. Is there another way ?? CAN I PULL THE TRIGGER ON MY HEAD YET!!


#6


#7

I have noticed the missing {} for greeting function, maybe it's this.
If it won't work try to restart your computer or open this lesson from another browser.