FAQ: Learn Handlebars - Handlebars "Else" section

This community-built FAQ covers the “Handlebars “Else” section” exercise from the lesson “Learn Handlebars”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Building Interactive JavaScript Websites

FAQs on the exercise Handlebars “Else” section

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 (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 (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

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:

  1. User inserting the exact amount of $
  2. User inserting too much $ (for change)
  3. 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)?

Thank you in advance!

2 Likes

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?

Have you found any solution to this ? i tried but didn’t get the result.