Intro to Functions in JS Unit 2 Exercise 5


#1

https://www.codecademy.com/courses/javascript-beginner-en-6LzGd/0/5?curriculum_id=506324b3a7dffd00020bf661

// 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)))}

Answer:
var greeting = function(name) {
console.log("Great to see you" + " " + "Manshi")
greeting ("Manshi")
}

I don't know what i am doing wrong here.
secondly how do you call a greeting's function after fixing the code given


#2

this line:

console.log("Great to see you" + " " + "Manshi")

you shouldn't use "Manshi", you should use the function parameter (name)

The function call:

greeting ("Manshi")

should be after the function, currently it is inside your function


#3

so it should be like this

console.log("Great to see you" + " " + "name")
greeting ("Manshi")


#4

except name is a variable (function parameter) so it shouldn't have quotation marks ("), this way it will display the value you pass in as argument when you call the function

impossible to tell if the function call is now outside the function call (after })


#5

When I type in the answer i get SYNTAX ERROR: Missing Before Statement

var greeting = function(name) {
console.log("Great to see you" + " " + "Manshi")
greeting (Manshi)
}


#6

name is a variable, and it should be without quotation marks, "Manshi" should still be a string in the function call, and your function call should be outside the function


#7

should still be a string in the function call, and your function call should be outside the function

I am not understanding the second part, of the string being in function call


#8

a function can have a parameter:

var example = function(parameter):
   console.log(parameter)
}

now parameter is a variable inside the function, which gets a value when you call the function:

example("this is what the function will log")

#9

var greeting = function(name) {
console.log("Great to see you" + " " + name)
}
greeting ("Hello")

Is it supposd to look like this?


#10

yes


#11

But it's still giving me
SyntaxError: missing before statement


#12

can i see your full code? You did remove the badly written function, right?


#13

yes the code i gave was the fully written code that i was submitting for the answer


#14

If that is your full code, it should work. Try a different browser


#15

ok i will try that then


#16

It's still not letting me, I'm still stuck :frowning:


#17

can i see all the code you have in the exercise?


#18

This is the line [line 9] i have to fix :

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

Instructions are as follows:
A big part of programming is debugging. That just means figuring out
what the heck went wrong with your code. Why didn't it run?

1. Look at line 9. It has many syntax errors. See how lack of spacing makes debugging hard?

2. Fix the function on line 9. Make sure the syntax is right. Make sure it looks nice.

3. Call the greeting function once it is fixed! Don't forget to pass in a specific name


#19

Can i see the full code you have in the file?"


#20

I don't understand by what you mean by > full code you have in the file.