Week 2 - Programming basics

JavaScript

Basic Syntax

Variables

Data types

Numbers

Basic IO

Conditionals

Nested conditions

Git branches

GUI Tools for Git

Code style: Basics

Introduction to AI

Practice

Assignment

Back to core program

Week 2 Assignment

Task 1 - Leap Year Check

A leap year has 366 days instead of 365, with February receiving an extra day. Here are the rules for determining a leap year:

  1. A year is a leap year if it is divisible by 4
  2. However, if the year is divisible by 100, it is not a leap year
  3. Unless the year is also divisible by 400, in which case it is a leap year

Examples:

Requirements

Write a JavaScript application that gets a valid year from a prompt and prints one of the following outputs:

Replace <YEAR> with the year provided by the user.

A Valid year is between 1 and 9999.

Additional Instructions

Task 2 - Login screen

In this task, you are asked to write the logic for a login page in an application. Our designers created this nice looking login screen:

image.png

In the task-2 folder, you will find multiple files. The only file you will be working on is login.js. You can ignore the rest of the files as they only support the design and basic events of the login screen.

Requirements

  1. On a correct username and password combination, show a success message “Logged in successfully”
  2. On a wrong username and password combination, show an error message “Incorrect credentials”.
  3. If the user inputed the wrong password for more than 3 times (4 or more), block the login page.
  4. If the login place is blocked, show an error message “Login blocked: Too many incorrect attempts” regardless if the credentials are correct or not

The applications has two valid users:

Username Password
admin Hack1234
user 7654321

Additional Instructions

<aside> 💡

You can run the code using the recommended Live Server VSCode plugin.

</aside>

Task 3 - Currency converter app

You have been assigned to fix a couple of bugs in a currency convert app that was built by another developer. In task-3 you will find a file called converter.js that contains the code of the application. The application should work in the following way:

  1. Ask the user to choose 1 or 2 to select which currency they want to convert to (the target currency).
    1. Reject any other options with a message.
  2. Ask for the amount in the base currency
    1. Reject invalid non-numeric or negative amounts
  3. Calculate and display the amount in the target currency.

Here is an example input of the working application

Hello and welcome to the currency converter. Please choose: 
1: Convert EUR to USD
2: Convert USD to EUR
Select your option [1 or 2]: 1

Enter amount in EUR: 150
150.00 EUR is equal to 174.64 USD.

Requirements

  1. Fix 3 bugs (see below)
  2. Implement one feature (see below)

Instructions

Bugs to Fix

Unfortunately, the code has some issues, and it's up to you to find and fix these bugs:

  1. The application won't run at all. There's an error in the console when you try to run it. Check the console and try to understand what's wrong. VSCode can also give you a hint.
  2. After fixing bug 1, the application runs, but the conversion from USD to EUR fails with a new error message in the console. Investigate this error by reading the console message carefully.
  3. The conversion from EUR to USD isn't working either. We always get the message "Please enter a valid positive number for the amount" when we type a valid amount like 100. There's no console error here because this is a logical error in the application. Review the code for the EUR to USD conversion and see if you can spot the issue.

Feature to implement

Add a third option (number 3) to display the current exchange rate. The output should look like this:

Hello and welcome to the currency converter. Please choose: 
1: Convert EUR to USD
2: Convert USD to EUR
3: Display the current exchange rate
Select your option [1, 2, or 3]: 3

The current exchange rate is 1 EUR = 1.1643 USD.