Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

116
Views
Using a ternary expression in React

In this component:

 const MovieComponent = (props) => {
  const { Poster, Price, Title, cinemaWorldPrice } = props.movie;

  return (
    <MovieContainer>
      <CoverImage src={Poster} alt="" />
      <MovieName>{Title}</MovieName>

      <InfoColumn>
        <MovieInfo>FilmWorld: ${Price}</MovieInfo>
        <MovieInfo>CinemaWorld: ${cinemaWorldPrice}</MovieInfo>
      </InfoColumn>
    </MovieContainer>
  );
};

I'm wanting to write a ternary expression that will change the font color of:

<MovieInfo>FilmWorld: ${Price}</MovieInfo>
        <MovieInfo>CinemaWorld: ${Price}</MovieInfo>

Something basically saying

if (Filmworld Price > CinemaWorld Price) { Filmworld Price = color: "green"}

and vice versa. Is this possible? And would the code be in the movie info section? This is on React.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to

  • properly interpolate the prices into JSX (${} is only for template literals)
  • surround the price texts in another element, like a span, so you can then conditionally color that span if needed
const MovieComponent = (props) => {
    const { Poster, Price, Title, cinemaWorldPrice } = props.movie;
    return (
        <MovieContainer>
            <CoverImage src={Poster} alt="" />
            <MovieName>{Title}</MovieName>
            <InfoColumn>
            <MovieInfo>
                    FilmWorld:
                    <span style={Price > cinemaWorldPrice ? { color: 'green' } : null}>{Price}</span>
                </MovieInfo>
                <MovieInfo>
                    CinemaWorld:
                    <span style={Price < cinemaWorldPrice ? { color: 'green' } : null}>{cinemaWorldPrice}</span>
                </MovieInfo>
            </InfoColumn>
        </MovieContainer>
    );
};
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!