Will somebody please explain how to do 7/8


#1

I do not even know where to begin with this one. Somebody please help.


#2

please, show us the print- image.. or write the code plus instructions , thank you!
that way , we can save time and help you right away :blush:


#3

// Parameter is a number, and we do math with that parameter
var timesTwo = function(number) {
return number * 2;
};

// Call timesTwo here!
var newNumber =
console.log(newNumber);

On line 7, after the equals sign, call the function timesTwo with any parameter you want
Line 8 prints out newNumber. Notice how the value we return from timesTwo() is automatically assigned into newNumber.


#4

Well you call a function by functionName(arguments) so in your case by e.g. timesTwo(42). And you assign a value by variable = value so yes the exercise is as easy as it sounds:

var newNumber = timesTwo(42);
console.log(newNumber);

It's more or less to see how a function is working. But better play a bit with it to get used to how functions are called and paramters are used to obtain different outputs for different inputs.


#5

I've explained functions before, but if necessary I'll give a "small" reminder. :stuck_out_tongue:

<><><><><><><><><><><><><><><>Functions<><><><><><><><><>
The basic formula for a function is this:

var functionName = function(arguments) {
do something here
}
To call a function, it looks like this.functionName(arguments);
Now, let's talk about each of these elements in turn. First, you have to make your function's name. Simple, and the standard way to name it is one word made of two, the second capitalized. Next is what makes your function, well, a function. Telling the computer that it's a function is just the word "function" before your arguments. Hold up-- what's an argument? This is a temporary "variable" you will "declare" when you call the function. It tells the computer the things it will need to know in order to run the function. For example, in this function, the only argument is "price". The price is, as I said, what the computer needs to know in order to run the function. If it didn't know what "price" was, then it wouldn't have any numbers to run the function with. The key here is thinking like the computer.
The next part is simple. You tell the computer what you want it to do. For example, here you want it to multiply the price of the oranges by five and print that out onto the console, so you'd type:
console.log(price*5) as you did. Also, it's never a bad idea to add a semicolon after console.log. Then, you close what you want to do with the curly brackets.
Finally, calling the function. Make sure you call the function outside of the function. How you do it is: first, you type in which function you want to call, then declare your argument "variables" in parentheses. Here, the orange cost is 5, so you type in 5 in the parentheses obviously. A semicolon finishes your calling, and -- Voila! A function!
Hope it helped.