#Conditional Class based off props. What am I doing wrong?

1 messages · Page 1 of 1 (latest)

vast cedar
#

On line 10 I am trying to only add the passed classes via props else show a default class. Getting ERROR: Expected ")" but found ":"

jovial tinsel
#

You probably want ? instead of &&

vast cedar
#

You are so good to me!

#

Is this syntax specific to Astro or is there a resource I can view to deep dive into the expressions?

jovial tinsel
#

It's just normal JS syntax 😄

#

What you were trying to do in that screenshot is called a ternary operator: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator

The conditional (ternary) operator is the only JavaScript operator that takes three operands:
a condition followed by a question mark (?), then an expression to execute if the condition is truthy followed by a colon (:), and finally the expression to execute if the condition is falsy.
This operator is frequently used as an alternative to an ...

vast cedar
#

See what relying on jQuery for 15 years has done to me!

#

Thank you so much for your help as always @jovial tinsel