Lesson 6:is my code correct?


#1



Replace this line with your code. 
orangeCost=function(value){
    var val=value*5;
    console.log("the cost is "+" "+val);
}
orangeCost(5);

my answer is 25 but still it says " it looks like your orangeCost() function doesn't return 25 when the cost of an orange is 5."


#2

@jay8978

I mean, technically it looks okay to me but seems a bit repetitive (this is the "D.R.Y." chapter, after all)... Can you see any line that may be unnecessary in your code?

frisby


#3

yes got it , i removed the console.log ,thanks a lot ,@msfrisby


#4

checker means what it kinda cecks the code for any errors?


#5

Hi @jay8978,

No problem! But I went back and looked at the instructions for this exercise and think I gave you the wrong advice, sorry. Can you please check my edited answer?


#6

Yes, that is what I mean by "checker". :slight_smile: But when I use it not necessarily for "errors" but "did you meet lesson objectives"


#7

cool thanks! nice to meet you


#8

Nice to meet you, too.

Were you able to figure out how to streamline your code while including console.log?

frisby


#9

i didnt get you ? you mean did i understand how to include console.log?


#10

Yep, in my original answer I suggested you might remove console.log because only one of the two lines are really needed to calculate the cost, but when I looked at the instructions they said they want you to print the cost (you need to use console.log). (This is when a link to the lesson can come in handy.)

So my question is: did you figure out how you can eliminate one line of your program while being sure to keep console.log?


#11

when i am trying to include console.log , there's an error(i tried to reduce line) so can you please send me the code of what it is ?


#12

@jay8978, why don't you share your code instead? :nerd:

Put it between two lines of three backticks (`) like this:

```
(your program)
```


#13

orangeCost=function(value){
var val=value*5;
}
orangeCost(5);

@msfrisby please tell me where to add console.log


#14

@jay8978 Just looking at your program without making any changes, if you had to choose one line to print which would it be?


#15

it is the second line i guess @msfrisby


#16

Yep, you're getting it! Anything else on that line seem like it could be whittled down?


#17

console.log("the cost is "+" "+val);//wrong
console.log(val) //right
just console.log(val)
not anything else
or
return "the cost is "+" "+val; instead of console.log(val)

@jay8978


#18

Hi! I just faced the same issue and decided to browse the forums for answer.
I find your response very helpful, however,
I would really appreciate it if you can explain a bit further.
Why does console.log("the cost is "+" "+val); print the response twice, and why is it wrong to use
console.log("the cost is "+" "+val);

@rcodeman


#19

@antonxx see this post re printing twice (generally).

iirc this exercise wants you to call your function and the function should print your sentence. If you print it below then you may be doing the work twice but I'd have to see the full program to be sure.


Whats wrong with my code?lesson 11
#20

It makes sense. Thanks for the information.