6. Dont Repeat Yourself stumped on math


#1



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

var orangeCost = function(cost) {
var price = 10;
var total = price *5;

console.log(total) }
orangeCost()Oops, try again. Hmm, it looks like your orangeCost() function doesn't return 25 when the cost of an orange is 5.

Replace this line with your code.


#2

got this weird error code i am confused how does make sense?

var orangeCost = function(cost) {
var price = 10;
var total = price *5;

console.log(total) }
orangeCost()

Oops, try again. Hmm, it looks like your orangeCost() function doesn't return 25 when the cost of an orange is 5.

i do not understand this at all


#3

Hi coreplayer :slight_smile:

Oops, try again. Hmm, it looks like your orangeCost() function doesn't return 25 when the cost of an orange is 5.

The exercise wants you to return the value. Now see what you are doing:

// where is the return statement?
var orangeCost = function(cost) {
var price = 10;
var total = price *5;

console.log(total) }
orangeCost()

Can you now fix the error? :wink:


#4

return the value? i dont know how to put it i keep getting syntax error


#5

Ok, sorry, I found your mistake:

var orangeCost = function(cost) {
    var price = 10; 
    var total = price *5;

You do not have to multiply by 5 your own value. As per instruction 4,

It should take a parameter that is the cost of an orange, and multiply it by 5.

Reading it carefully, we find that total should be equal to the parameter (cost) multiplied by five. Can you now fix the error? :wink:


#7

yes okay i have fixed it thank you. but i am still confused why it would give an error message as if it was mathematically incorrect


#8

if it was mathematically incorrect

Well, it was incorrect according to the instructions of the exercise :slight_smile:


#9

This java tutorial is 10x worse than any other lessons I've seen on this site.


#10

This is Javascript. Before randomly criticising a course, make sure you know which one you want to criticise.

I personally thought that it was a great course, and now I know a lot more than I did by using books prior to joining Codecademy in 2014.


#11

u haven't seen python then


#13

This JavaScript tutorial is very good i think.
First check the programming language we are using here, then understand the problem by reading the instructions as many times as you need to, finally criticize in a constructive way always!