Graalians

Graalians (https://www.graalians.com/forums/index.php)
-   Off-Topic Chat (https://www.graalians.com/forums/forumdisplay.php?f=14)
-   -   Codecademy (https://www.graalians.com/forums/showthread.php?t=22233)

HappyCat123 12-20-2013 08:14 PM

gosh darn curly brackets screwing up all my stuff.

PoeticFolly 12-21-2013 12:17 AM

I really like this. But I can never really get into it for more than a few weeks. I'll just drop it one day. I do that with a lot of things though.

Platinum 12-23-2013 09:44 AM

I need a bit of assistance with the JavaScript tutorial. If anyone could help me, I would be grateful! These are the instructions:
You are a creature of habit. Every week you buy 5 oranges. But orange prices keep changing!
1. You want to declare a function that calculates the cost of buying 5 oranges.
2. You then want to calculate the cost of the 5 all together.
3. Write a function that does this called orangeCost().
4. It should take a parameter that is the cost of an orange, and multiply it by 5.
5. It should log the result of the multiplication to the console.
6. Call the function where oranges each cost 5 dollars.
-----this is what I coded so far ---
var orangeCost = function (orangeCost) {
var price = number * 5
}
console.log(price = 4)

iDylan 12-23-2013 10:27 AM

Quote:

Posted by Platinum (Post 438325)
I need a bit of assistance with the JavaScript tutorial. If anyone could help me, I would be grateful! These are the instructions:
You are a creature of habit. Every week you buy 5 oranges. But orange prices keep changing!
1. You want to declare a function that calculates the cost of buying 5 oranges.
2. You then want to calculate the cost of the 5 all together.
3. Write a function that does this called orangeCost().
4. It should take a parameter that is the cost of an orange, and multiply it by 5.
5. It should log the result of the multiplication to the console.
6. Call the function where oranges each cost 5 dollars.
-----this is what I coded so far ---
var orangeCost = function (orangeCost) {
var price = number * 5
}
console.log(price = 4)

oh **** i struggled with this one way to long too when i had this task. If you find yourself being stuck at certain tasks, just google the error/task. There's always an answer online!

---

try this;

var orangeCost = function (price){
var cost = price * 5;
return (cost);
};

orangeCost(5);

Platinum 12-23-2013 10:35 AM

http://i.imgur.com/I1MvyfF.jpg

iDylan 12-23-2013 10:58 AM

Quote:

Posted by Platinum (Post 438342)

var orange = 5;
var orangeCost = function (price) {
console.log(orange * 5);
};

orangeCost();

Platinum 12-23-2013 11:12 AM

It worked, thanks iDylan!

iDylan 12-23-2013 10:47 PM

Quote:

Posted by Platinum (Post 438349)
It worked, thanks iDylan!

no problemo :]

Nyte* 12-24-2013 03:26 PM

Quote:

Posted by Platinum (Post 438325)
I need a bit of assistance with the JavaScript tutorial. If anyone could help me, I would be grateful! These are the instructions:
You are a creature of habit. Every week you buy 5 oranges. But orange prices keep changing!
1. You want to declare a function that calculates the cost of buying 5 oranges.
2. You then want to calculate the cost of the 5 all together.
3. Write a function that does this called orangeCost().
4. It should take a parameter that is the cost of an orange, and multiply it by 5.
5. It should log the result of the multiplication to the console.
6. Call the function where oranges each cost 5 dollars.
-----this is what I coded so far ---
var orangeCost = function (orangeCost) {
var price = number * 5
}
console.log(price = 4)

Mother of god, I was stuck on this one weeks ago and haven't logged on since, thought I was gonna break my keyboard.

Dusty 12-24-2013 05:25 PM

Quote:

Posted by iDylan (Post 438345)
var orange = 5;
var orangeCost = function (price) {
console.log(orange * 5);
};

orangeCost();

Shouldn't it be:

var orange = 5;
var orangeCost = function (price) {
console.log(orange * price);
};

orangeCost();

I thought the point of it was that the price is always changing, hence why the function takes a parameter for the price.

iDylan 12-25-2013 09:20 PM

Quote:

Posted by Dusty (Post 438611)
Shouldn't it be:

var orange = 5;
var orangeCost = function (price) {
console.log(orange * price);
};

orangeCost();

I thought the point of it was that the price is always changing, hence why the function takes a parameter for the price.

oh i see what i did wrong x-x. It still worked tough, but that seems much more logical:).

Platinum 12-25-2013 09:56 PM

var myFunction = function (Parameter)

Is the parameter a variable?

Imprint 12-25-2013 10:01 PM

The parameter is the variable you input into the function.

BboyEatsbacon 12-25-2013 10:08 PM

Quote:

Posted by Platinum (Post 438860)
var myFunction = function (Parameter)

Is the parameter a variable?

Quote:

Posted by Imprint (Post 438863)
The parameter is the variable you input into the function.

Yes. So, for example:

PHP Code:

var multiplyByTwo = function (number) { // Define first passed variable (parameter) as 'number'.
   
return number 2// Use the function to return a number result of input number times two.
};

console.log(multiplyByTwo(5)); // Pass two as a variable 

would log 10 into the console.

Platinum 12-25-2013 10:17 PM

Quote:

Posted by Imprint (Post 438863)
The parameter is the variable you input into the function.

Quote:

Posted by BboyEatsbacon (Post 438866)
Yes. So, for example:

PHP Code:

var multiplyByTwo = function (number) { // Define first passed variable (parameter) as 'number'.
   
return number 2// Use the function to return a number result of input number times two.
};

console.log(multiplyByTwo(5)); // Pass two as a variable 

would log 10 into the console.

So the parameter's value is assigned after the function has been coded?


All times are GMT. The time now is 02:06 PM.

Powered by vBulletin/Copyright ©2000 - 2025, vBulletin Solutions Inc.