Functions


#1

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?

Look at line 9. It has many syntax errors. See how lack of spacing makes debugging hard?
Fix the function on line 9. Make sure the syntax is right. Make sure it looks nice.
Call the greeting function once it is fixed! Don't forget to pass in a specific name.

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

i dont know how to call the greetings and to fix line 9 i think this is how but I'm pretty sure its wrong.
9: calculate (20)


#2

var means variable

calculate is the name of your variable

= the equals sign means calculate is the name for something, could be a number, boolean, string, object, etc

function calculate will be a function

(number) parameters go inside parentheses

{ the curly brace is what you write before the code for what you want the function to do

var val another variable

= number * 10; val means multiply the parameter by 10

console.log(val); console.log tells javascript to print something to the display, whatever you want to display goes inside parentheses

};a closing curly brace ends your function declaration

The complete calculate function looks like:

var calculate = function(number) {
var val= number*10;
console.log(val);
};

To call the calculate function, you would write;

calculate(10);

Let me know if anything is unclear. Now it is up to you to take this:

And fix it :slight_smile:


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.