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
Running a conditional for my front-end application to return a string if the value of a property returns null

Below is my code. I have already ran "musical" through a console log and can confirm it is returning my state data. My goal is because not every object that has "buy-price" has a value to it(some return null as the value), I want to run this conditional where it can give a string that alerts users "this is not for sale" if null, or return the correct price if it does exist in the API.

import React, { useEffect, useState } from "react";
import fishes from "../APIs/animalCrossing";

export default function Music() {
  const [music, setMusic] = useState([]);

  useEffect(() => {
    fishes.getVillagerMusic().then((response) => {
      setMusic(response);
    });
  }, []);

  const buyMusic = () => {
    music.map((musical) => {
      if (musical["buy-price"] == null) {
        return "This Song is not for purchase";
      } else {
        return musical["buy-price"];
      }
    });
  };
  return (
    <div>
      {music.map((music, index) => {
        return (
          <div key={index}>
            <img src={music.image_uri} alt="music" />
            <p> Sold at: ${buyMusic()} </p>
          </div>
        );
      })}
    </div>
  );
}
about 4 years ago · Juan Pablo Isaza
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!