Lab 14


All work must be your own! If you copy from someone else you will receive a zero (at best).

Create an HTML page that uses JavaScript to convert U.S. dollars to a currency of your choosing.

  1. Using Notepad++ create a valid HTML document named "Converter.html". Include the necessary tags for title, body, etc. Set the page title to "Currency Converter". Ensure you can view your page using a browser before you continue.

  2. Choose a currency, other than Thai baht, you wish to convert to. Search to find the current exchange rate. Record the URL you used to find the exchange rate. If you use baht you will receive a zero.

  3. Create two paragraphs with the following text.

    This converter uses the exchange rate as of 4 Dec 2013 according to www.xe.com: 32.2300 Thailand baht per U.S. dollar. 
    
    Reload the page to convert another amount. 
    
    Replace the date with the current date. Replace the URL with the one from step 2 and make it a link. Replace the exchange rate with the one from step 2.
  4. Add the following text to the head section of your document.

      <script>
        var dollars = prompt ("Enter amount in U.S. dollars:");
        alert ("You entered $" + dollars + ", which is not a lot.");
      </script>
    
    Reload your web page and notice what happens. The script tags enclose JavaScript code. Carefully study the code and read the hints below.
  5. Modify the code so the alert box displays the following.

    $[input value] is [converted value] [currency]. 
    
    Replace the bracketed text with the values from your program. For example, in my case the user entered 23 dollars. So my output is "$23 is 741.29 Thailand baht.". Review your notes and chapter 17. You should not need more than 5 lines of code.
  6. Use at least one variable (besides "dollars"), preferably two, in your code.

  7. Ensure your code is general and works for any valid input. If your code only works for one value you will receive no credit.

Submit your HTML file as assignment "Lab14".

Ensure you submit the correct file. If your file cannot be opened you will receive a zero. If you submit the wrong file it will be graded as is. No exceptions will be made.


Extra Credit

Modify the code to use text boxes rather than pop-up dialogs.

Here's an example.

Enter your age:
Your age in five years:


Hints

JavaScript supports functions like "prompt" and "alert". The "prompt" function displays a pop-up dialog with the text you specify, and an input field. When the user types a value and presses "return", or clicks "OK", the entered value is assigned to the variable on the left side of the equal sign.

The "alert" function displays a pop-up dialog with the specified text. It is used to output results to the user.


Gary M. Zoppetti