html.edx.project
html.edx.project
Objectives:
1. Download the project folder.
2. Modify the HTML file as per the requirements.
3. Modify the CSS file as per the requirements.
4. Modify the JavaScript file as per the requirements.
5. Verify that the webpage is working properly.
This lab environment does not store your changes across multiple sessions. To avoid losing your work, please complete your
project in one session or store your files elsewhere and add them back here to continue at another time.
2. Paste the following commands into your terminal to download the project folder and unzip it
1. 1
1. wget https://github.com/ibm-developer-skills-network/vftvk-Simple-Interest-Calculator/archive/refs/heads/master.zip
Copied! Executed!
1. 1
1. unzip master.zip
Copied! Executed!
3. Open the file explorer and verify that the project contains the following files:
index.html
style.css
script.js
4. Throughout this project, you will need to test your web page using the Live Server extension. For steps on how to use the extension,
click here. Note that opening Live Server will only work if you click on the index.html file, it will not appear for any other file type.
2. All HTML files must begin with a doctype tag, to indicate that HTML content will be placed in the file. Add this tag to the beginning of
index.html.
3. Use the title tag to change the browser title to be “Simple Interest Calculator”. Remember that the title tag should be placed in the
head section of your markup.
4. Move all the content which is currently in the <body> to a new <div> tag.
6. Modify the input id="rate" tag for the interest rate to be a slider. Recall from earlier lessons that this can be done by changing the type
to range.
1. 1
Copied!
7. For the rate input, add the following attributes and their corresponding values:
Click here to see the code for the interest rate tag after making the above updates
Range is an elegant way to input numeric input, but the drawback is that it does not visually show value the user has selected.
8. To show the value selected by the range, create a <span> element right after the range, with the id rate_val.
9. Inside the <span> tag, add the text “10.25” to represent the default value (as specified above). Add a “%” outside this span tag. The span
will be updated dynamically later on, but the “%” should always remain, so this is placed outside the tag.
Insert a line break after this tag, so the next input appears on a new line.
10. Modify the input text box for “No. of Years” into a dropdown box with options 1 to 10.
Recall from the “HTML5 Input Element” video, the correct way to insert a dropdown in HTML
12. Below the “Compute Interest” button, create an empty <span> and set its id to result. This will be used to dynamically display the result
of the calculation when the “Compute Interest” button is clicked.
13. Outside the maindiv, add a copyright message using the <footer> tag, like below:
1. 1
2. 2
3. 3
1. <footer>
2. © This Calculator belongs to --your name--
3. </footer>
Copied!
15. Open your application using the Live Server extension and make sure that you have not missed anything. Your page should look
similar to this:
2. Set the body background color to ‘black’, font family to ‘arial’ and font color to ‘white’.
Click to see how the new `maindiv` class should look like
7. Open your application using the Live Server extension and make sure that you have not missed anything. Your page should look
similar to below:
1. Create an empty function called updateRate(). This will be used to display the value of the ‘Rate’ slider.
2. Inside the updateRate() function, create a variable rateval that gets the value from the ‘Rate’ slider.
3. Modify the <span id="rate_val"> value to display the value of the rateval variable created above.
5. Save the file and open your web page with the Live Server extension. Change the slider and verify that the value to the right of it
updates with a new value each time the slider is changed.
If this does not work as expected, go back to your code to identify where the problem is.
1. Create the following variables inside the compute() function, and assign them to the corresponding value listed:
principal initialized to the value of the input element with an id of principal, parsed as an int. This is needed to calculate the final
amount, as well as the interest amount
rate initialized to the value of the input element with an id of rate, parsed as a float. This is needed to calculate the interest amount
years initialized to the value of the input element with an id of years, parsed as an int. This is needed to calculate the interest amount
interest with the value principal * num_years * rate / 100. This is needed to calculate the total amount
amount which is the sum of the integer value of principal and the float value of interest
result initialized to the input element with an id of result. This is needed to modify the text when the Compute button is pressed
2. Write the logic to convert the ‘No. of Years’ into the actual year in the future. This can be done by adding the number of years (years)
to the current year inside the compute() function.
This will ensure that the input taken as “No. of Years” is converted into an actual year (e.g. 2022).
3. Add validation for the “Principal” input box. If the user enters zero or a negative value, show an alert which says “Enter a positive
number”
4. Once the user clicks on the alert “OK” button, take the user back to the “Principal” input box, by setting the focus on this box using the
focus method in the code for principal input validation:
5. Within an else clause, set the inner html property of the result to the text below, replacing anything within the square brackets [] with
its actual value.
Note that when writing < or > within quotation marks, you must instead type \< or \>
1. 1
2. 2
3. 3
4. 4
Copied!
6. Make sure the numbers in the result are highlighted by using the mark HTML tag around each variable value:
1. 1
2. 2
3. 3
1. else {
2. result.innerHTML = "If you deposit $" + "<mark>" + principal + "</mark>" + ",\<br\> at an interest rate of " + "<mark>" + rate +
3. }
Copied!
Write comments in your code which will help debug and maintain the code in the long term.
Other Contributor(s)
Michelle Saltoun