New to Javascript!

Hey everyone!

I’m an absolute beginner when it comes to Javascript and in the course I’m doing I’ve been asked to perform the following operation; Find the value of the price property, and if it is greater than 100, discount it by 10%. if that’s not the case, discount it by 7%.

Here’s what I have, my knowledge of Syntax is very basic… any help would be appreciated!


let product = {
  name: 'Screen',
  price: 100,
};


console.log(product.price)

if (price > 100) {
  console.log (price * 0.9);
  }
else  {
 (price <= 100) {
console.log (price * 0.93)
 }

Hi!

I show you the way how to do it but further optimization is necessary:

product = {
name: "Screen",
price: 99,
};

if (product.price > 100) {
     console.log (product.price * 0.9);
}
else {
     console.log (product.price * 0.93);
}

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Hey Rielka!

Thanks so much for your help! I gave it a try but for some reason I kept getting syntax errors back? I must have done something wrong! Thanks so much for your help though!

Hey ArielLeslie!

Oh, sorry about that! I’ll remember that for next time!
Thanks!

What syntax errors are you getting?

In the end it was just me getting confused by the fact that when I was writing the code in codepen.io it was constantly refreshing as I was writing the code and telling me I had syntax errors! I’ve just given it another try and this time it seems to be working perfectly! :slight_smile: I’ve decided to turn off the auto-refresh feature as I find it quite confusing.

Thanks again for being so helpful!