Why does this code not work?


#1


I'm having a lot of trouble when it comes to creating code from scratch. I looked around at answers and saw how this is supposed to look, but for some reason I can't understand why this doesn't work. Can anyone explain to me why this is wrong? I declared the variable "price" to be "5" for 5 dollars, so why is the console not showing the solution of 5 * 5?


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


SyntaxError: missing before statement


var price = 5
console.log"orangeCost(price * 5)"


#2

how console.log works

console.log( )

anything you want to see in the console put in the parenthesis.if its string value then it should be inside " " like

console.log("some string value")

if its number then

console.log(5) // without quotes

so in your case it should be

console.log("orangeCost "+(price * 5))

orangeCost is string value and (price*5) is number



but in the that lesson you have to create a function.did you create that?if yes, can i please see your full code?

for the calling the function it would be like

console.log(functionName(argument))


#3

That actually was my whole code. I had to go look up how to code functions on YouTube to better understand how the coding works. Looking back at it, I'm still a bit confused over what the best coding would be for inside the function or curly braces. I saw console.log( cost * 5) and tried that, which seemed to work, but after passing that section and seeing the others, it seemed off to me. Maybe I was expecting something more complicated? So I went back and just simply put in cost * 5, which also seemed to work. I then tried out return cost * 5, which also worked. Am I overcomplicating this? What was the initial intention behind this specific lesson?


#4

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