Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Lab 10 – Javascript Functions with Conditionals

Objectives

.    Creating applications that use Javascript functions with conditionals

.     Using global variables

What to do in Lab?

1.    Log in to the computer. If you are reading this, you must have done this already. 2.    Create CPSC1045\Lab10 folder

3.    Download the file Lab10.zip from D2L to your system. Unzip the contents into your Lab10 folder. 4.    Open the included HTML document named lab10.html in Google Chrome by either double

clicking (if Chrome is the default browser) or by right clicking on it in your file explorer and then selecting Open With -> Google Chrome. The document looks as follows:

5.    Now open the lab10.html file using your favorite HTML editor such as Brackets or VS Code, so that you can edit the code. You will need to create a JS file named lab10.js in which you can write your functions and link it to lab10.html.

Part 1 (5 marks)

6.    Write a function named makeDeposit()that takes the amount from the box below Deposit Funds and passes it to another function named deposit(). It then calls the function display()which displays the balance within the element with the id "display". The deposit()function does the following:

.     If the deposited amount is zero, negative, or not a number, the function displays the message "Invalid amount." within the element with id "message".

.    Otherwise, the function adds the amount to the balance and displays the message " Your balance is: balance" within the element with id "message".

Part 2 (5 marks)

7.    Write a function named makeWithdrawal()that takes the amount from the box below

Withdraw Funds and passes it to another function named withdraw(). It then calls the

function display()which displays the balance within the element with the id "display". The withdraw()function does the following:

.     If the withdrawal amount is zero, negative, or not a number, the function displays the message "Invalid amount." within the element with id "message".

.    Otherwise, if the withdrawal amount is greater than the balance, the function displays the message "Insufficient funds." within the element with id "message".

.    Otherwise, the function subtracts the amount from the balance and displays the message "Your balance is: balance" within the element with id "message".

Hint: You can use the isNaN() function to check whether the amount is a number or not.

The finished document should look as follows:

Submission: What to hand in

Zip the folder Lab10 which contains your source code (the edited file lab10.html and the lab10.js file you created) and upload it to D2L.

Submission: When to hand in

At the end of the lab period.