Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Implement Conditional Rendering in Bank Alert | Reusable Components and Data Flow
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Introduction to React

bookChallenge: Implement Conditional Rendering in Bank Alert

Swipe to show menu

Task: Creating a Bank Alert

Let's work with a bank account. We aim to develop a logic that informs the user whether they have sufficient funds on their card to cover a given price. Depending on the outcome, we will display different messages to the user.

The task is:

  • Create two components - App, parent, and Message, child.
  • The parent component (App) transfers the props moneyAvailable, price, and name.
    1. moneyAvailable - represents the amount of money the user has;
    2. price - denotes the amount of money the user needs to pay;
    3. name - refers to the user's name.
  • If the user has enough money to pay, we show the message: Success! The remaining amount of money for <user_name> is: <calculated_amount_of_money_left>. Thank you!.
  • If the user has not enough money to pay, we show the message: Failure! The bank account balance for <user_name> is: <moneyAvailable>. Unfortunately, you need to pay: <price>.
  1. In React, we use the ternary operatorย condition ? ... : ...ย to implement the logic of anย if...elseย statement.
  2. To construct the string correctly,
    • Replace the placeholderย user_nameย with the actual user name:ย nameย prop;
    • Replace the placeholderย calculated_amount_of_money_leftย with the calculated amount of money left -ย moneyAvailable - price;
    • Replace the placeholderย moneyAvailableย with the actual available money -ย moneyAvailableย prop;
    • Replace the placeholderย priceย with the actual price -ย priceย prop.
  3. Use curly bracesย {...}ย to assign a value that is not a string type.

Everything was clear?

How can we improve it?

Thanks for your feedback!

Sectionย 2. Chapterย 5

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Sectionย 2. Chapterย 5
some-alt