Giter Site home page Giter Site logo

simple-interest-calculator's Introduction

Project - Simple Interest Calculator

Objectives

  1. Clone the project repo.
  2. Modify the html file as per requirements.
  3. Modify the css file as per requirements.
  4. Modify the javascript file as per requirements.
  5. Verify if the app is working properly.
  6. Upload to GitHub and submit the github pages URL for peer review.

Exercise 1 : Clone the project repo.

  1. In the project prepration phase you have forked the project into your GitHub Account. Copy the URL from your repository.

  1. Open a new terminal.

  1. Clone the project repository onto your local machine or the Theia environment from the github fork, using the URL you copied in step 1.
git clone <paste your repo clone url here>

Exercise 2 : Modify the html file.

In this exercise, you will correct any mistakes in the existing code and also add any missing tags.

  1. On the file explorer navigate to the index.html.

  1. Doctype is missing. Add the doctype.
<!DOCTYPE html>
  1. Add "Simple Interest Calculator" as title.
<title>Any relevant title you want to give</title>
  1. Move all the content which currently is in the <body> to a <div> tag.

  2. Set the class attribute of this div to 'maindiv'.

<div class="maindiv">. . . .</div>
  1. Modify the input text box for interest rate to a slider using the <input type="range"> tag.
<input type="range" id="rate" min="minval" max="maxval" value="default_val" />
  1. For the rate input, set the attributes min to 1, max to 20 and step to 0.25 and the default value to 10.25.

Range is an elegant way to input numeric input. But the drawback is that it does not visually show value the user has selected.

  1. To show the value selected by the range, create a <span> element right after the range.
<span id="rate_val"> </span>
  1. Inside the '` tag add the text "10.25 %".
<span id="rate_val"> 10.25% </span>
  1. Modify the input text box for "No of years" into a dropdown box with options 1 to 10.
<select id="years">
  <option value="1">1</option>
  <!-- fill in the rest of the values-->
</select>
  1. Change the name of "Compute" button to "Compute Interest".

  2. Below the "Compute Interest" button create an empty <span> and set its id to 'result'.

<span id="result"> </span>
  1. Add a copyright message using the <footer> tag.
<footer>

        &#169; This Calculator belongs to --your name--


</footer>

Exercise 3 : Modify the css file.

In this exercise, you will correct the look and feel of the web page.

  1. On the file explorer navigate to the style sheet.

  1. Set the body color to 'black', font to arial and font color to white.
body {
  background-color: black;
  font-family: arial;
  color: white;
}
  1. Set the <h1> color to 'grey' and font to verdana.
h1 {
  color: grey;
  font-family: verdana;
}
  1. Create an entry for class 'maindiv'.
.maindiv {
}
  1. Set the background color to white, font color to black, width to 300 pixels, and padding to 20px in the newly created maindiv class.

  2. Set the border radius to 25 px.

  3. Align the div to the center of the page.

Click to see how the new class should look like
.maindiv {
  background-color: white;
  color: black;
  width: 300px;
  padding: 20px;
  border-radius: 25px;
  align: center;
}
  1. Visualize your html file in the browser and make sure that you have not missed anything.

Exercise 4 : Modify the javascript file.

In this exercise, you will write the javascript code in the file script.js to implement the simple interest calculation logic.

  1. Before we start writing any javascript, make sure that the button in html file has the onclick attribute set to "compute()"

  2. Create a variable called 'principal' and assign to it the value of the input element "principal"

var principal = document.getElementById("principal").value;
  1. Create a variable called rate and assign to it the value of the input element "rate"
var rate = document.getElementById("rate").value;
  1. Create a variable called years and assign to it the value of the input element "years"
var years = document.getElementById("years").value;
  1. Create a variable called interest and assign to it the value of principal * years * rate / 100
var interest = (principal * years * rate) / 100;
  1. Write the logic to convert the 'No of Years' into the actual year in the future.
var year = new Date().getFullYear() + parseInt(years);
  1. Write a function that reads the value of the range slider and displays it the <span>adjacent to the slider.
function updateRate() {
  var rateval = document.getElementById("rate").value;
  document.getElementById("rate_val").innerText = rateval;
}
  1. Link this function with an "onchange" event on the range input.

  2. Change the slider, and test if the display in the span is being updated dynamically.

  3. Get the reference to the element named 'result'

  4. When "Compute Interest" is clicked, set its inner html property to the below text.

    If you deposit 1000000,
    at an interest rate of 3.5%.
    You will receive an amount of 175000,
    in the year 2025

The number above are for indication only. Make sure the output contains the relevant values by using the correct variables

Click here for a sample
document.getElementById("result").innerHTML =
  "If you deposit " +
  principal +
  ",<br>at an interest rate of " +
  rate +
  "%<br>You will receive an amount of " +
  amount +
  ",<br>in the year " +
  year +
  "<br>";
  1. Make sure that the input you have taken as "No of Years" is converted into an actual year.

  2. Make sure the numbers in the result are highlighted.

  3. Add validation for "Principal" input box. If the user enters zero or negative values, show an alert "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. You can refer to the Javascript Form Validation lab.

  5. You are done with the coding. Let us proceed to next exercise where we test the code.

  6. Write comments in your code. They not only help you score more marks in the project, but also help you to debug and maintain the code in the long term.

Exercise 5 : Test the app.

Now that you have finished coding your app. Let us do some basic testing, before we release it.

  1. Enter these values in the form.

    Amount = 0

    Rate = 1

    No. of Years = 1

Click on Compute button.

You should see an alert "Enter a positive number".

  1. Enter these values in the form.

    Amount = 99999

    Rate = 9

    No. of Years = 9

Click on Compute button. You should see the following output.

If you deposit 99999,<br>
at an interest rate of 9.<br>
You will receive an amount of 80999.19,<br>
in the year 2029<br>

As I write this, the year is 2020, so 2029 is correct.

If you app has passed both the test cases, it is time to go to the next excercise.

Otherwise, start debugging your code to see where you went wrong.

Exercise 6 : Upload to GitHub and submit the github pages URL for peer review.

When you are done with all the changes in the project, commit and push to GitHub. You do not have to create a Push Request back to the original IBM repository.

If you need to refresh your memory on how to commit and push to GitHub in Theia lab environment, please refer to this lab Working with git in the Theia lab environment

Open the URL of your project in a browser. (You created this URL in Exercise 1)

You should see your completed project.

Submit this URL for peer review.

Author(s)

Ramesh Sannareddy

Other Contributor(s)

Rav Ahuja

Changelog

Date Version Changed by Change Description
2020-09-09 1.2 Lavanya Added some pics and explicit instructions
2020-09-09 1.1 Ramesh Sannareddy Added 'publishing to gitpages'
2020-08-23 1.0 Ramesh Sannareddy Initial version created

simple-interest-calculator's People

Contributors

neilmerin avatar ibm-skills-network-bot avatar rameshsannareddy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.