There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
Hello! I am new to programming, so please bear with me.
How do we accommodate scenarios where you have multiple if statements, such as the if...else statements in JS?
For example, if I was programming a self-checkout register, I would want there to be a possibility of:
User inserting the exact amount of $
User inserting too much $ (for change)
User not inserting enough $
What would be the correct code to write the above? Would it be something like this?
{{#if amount}}
<p>Thank you for your business! Have a nice day.</p>
{{else if}}
<p>Here is your change. Thank you for your business! Have a nice day.</p>
{{else}}
<p>Oops! You haven't inserted enough money. Please insert the balance.</p>
{{/if}}
To add on that, if I wanted the machine to display the remaining balance, could I concatenate the change due back in cases of overpayment (paid amount - balance), or the amount due in cases of underpayment (balance - paid amount)?
Excellent question,
I have tried to force the condition out of Boolean logic using an integer, like this:
{{#if amount = 3}}
and then
let context = {
amount = 3
};
But that doesn’t render anything… we would have to start by assigning a valid condition’s value to an integer or string in order to even use {{else if}}.
I have also tried using a colon ‘:’ instead of an equal sign ‘=’, but to no avail. Do any of you know how to get out of Boolean conditions for such an Handlebar statement?