JavaScript - Simple Temperature Converter
Submitted by razormist on Monday, January 14, 2019 - 16:53.
In this tutorial we will create a Simple Temperature Converter using JavaScript. JavaScript is a scripting or programming language that allows you to implement complex things on web pages. It is widely used in designing a stunning website. It is an interpreted programming language that has a capabilities of Object-Oriented. This code can be used as your calculator to any mathematical problem. So Let's do the coding...
There you have it we successfully created a Simple Temperature Converter using JavaScript. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
Getting started:
This is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.The Main Interface
This code contains the interface of the application. To create this just write these block of code inside the text editor and save this as index.html.- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
- <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
- </head>
- <body>
- <nav class="navbar navbar-default">
- <div class="container-fluid">
- </div>
- </nav>
- <div class="col-md-6">
- <hr style="border-top:1px dotted #ccc;" />
- <div class="col-md-6">
- <div style="border:1px solid #000; padding:20px; border-radius:10px;">
- <div class="form-group">
- <input type="number" id="fahrenheit1" placeholder="Enter number here" class="form-control"/>
- </div>
- <div class="form-group">
- <input type="text" id="celcius1" class="form-control" readonly="readonly"/>
- </div>
- </div>
- </div>
- <div class="col-md-6">
- <div style="border:1px solid #000; padding:20px; border-radius:10px;">
- <div class="form-group">
- <input type="number" id="celcius2" placeholder="Enter number here" class="form-control"/>
- </div>
- <div class="form-group">
- <input type="text" id="fahrenheit2" class="form-control" readonly="readonly"/>
- </div>
- </div>
- </div>
- </div>
- </body>
- </html>
Creating the Script
This code contains the script of the application. This code will automatically calculate the temperature of a person. To do this just copy and write these block of codes as shown below inside the text editor and save it as script.js inside the js folder.- function convertToCe(){
- var fahrenheit1 = document.getElementById("fahrenheit1").value;
- if(fahrenheit1 != ""){
- var number = parseFloat(fahrenheit1);
- document.getElementById("celcius1").value = (number - 32)/1.8 + "\xB0C";
- }else{
- alert("Please enter something");
- }
- }
- function convertToFa(){
- var celcius2 = document.getElementById("celcius2").value;
- if(celcius2 != ""){
- var number = parseFloat(celcius2);
- document.getElementById("fahrenheit2").value = (number * 9/5) + 32 + "\xB0F";
- }else{
- alert("Please enter something");
- }
- }
Add new comment
- 715 views