Challenge: Implement Conditional Rendering in Bank Alert
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, andMessage, child. - The parent component (
App) transfers the propsmoneyAvailable,price, andname.moneyAvailable- represents the amount of money the user has;price- denotes the amount of money the user needs to pay;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>.
- In React, we use the ternary operatorΒ
condition ? ... : ...Β to implement the logic of anΒif...elseΒ statement. - 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.
- Replace the placeholderΒ
- Use curly bracesΒ
{...}Β to assign a value that is not a string type.
Everything was clear?
Thanks for your feedback!
SectionΒ 2. ChapterΒ 5
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 4
Challenge: 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, andMessage, child. - The parent component (
App) transfers the propsmoneyAvailable,price, andname.moneyAvailable- represents the amount of money the user has;price- denotes the amount of money the user needs to pay;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>.
- In React, we use the ternary operatorΒ
condition ? ... : ...Β to implement the logic of anΒif...elseΒ statement. - 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.
- Replace the placeholderΒ
- Use curly bracesΒ
{...}Β to assign a value that is not a string type.
Everything was clear?
Thanks for your feedback!
SectionΒ 2. ChapterΒ 5