Advertisement
AyanUpadhaya

Celsius to Fahrenheit Converter in JavaScript

Oct 16th, 2021
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 2.27 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>Celcius to Fahrenheit</title>
  8.     <style>
  9.         .converter{
  10.             width: 500px;
  11.             margin: auto;
  12.             font-family: sans-serif;
  13.         }
  14.         label{
  15.             display: block;
  16.             font-weight: bold;
  17.             margin-bottom: 10px;
  18.             margin-top: 10px;
  19.         }
  20.         #celcius{
  21.             width: 300px;
  22.        
  23.         }
  24.         #fahrenheit{
  25.             width: 300px;
  26.        
  27.         }
  28.         .button-group{
  29.             margin-top: 20px;
  30.         }
  31.         #reset{
  32.             margin-left: 20px;
  33.             background-color: indigo;
  34.             border-radius: 20px;
  35.             color: ivory;
  36.             border:none;
  37.             outline: none;
  38.             padding: 5px;
  39.             width: 100px;
  40.         }
  41.         #convert{
  42.             background-color: indigo;
  43.             border-radius: 20px;
  44.             color: ivory;
  45.             border:none;
  46.             outline: none;
  47.             padding: 5px;
  48.             width: 100px;
  49.         }
  50.  
  51.     </style>
  52. </head>
  53. <body>
  54.     <div class="converter">
  55.         <h2>Celsius to Fahrenheit Converter</h2>
  56.         <form action="" id="newForm">
  57.             <label for="celcius">
  58.                 Celcius
  59.             </label>
  60.             <input type="text" id="celcius" name="celcius">
  61.             <label for="fahrenheit">
  62.                 Fahrenheit
  63.             </label>
  64.             <input type="text" id="fahrenheit" name="fahrenheit">
  65.             <br>
  66.             <div class="button-group">
  67.                 <input type="button" onclick="convertCelciusToFahrenheit();"value="Covert" id="convert">
  68.                 <input type="reset" value="Clear" id="reset">
  69.             </div>
  70.            
  71.         </form>
  72.     </div>
  73.     <script>
  74.         function convertCelciusToFahrenheit(){
  75.             let celcius = document.getElementById("celcius").value;
  76.             let fahrenheit = document.getElementById("fahrenheit");
  77.             let conversion = ((9/5)*celcius) + 32;
  78.             fahrenheit.value=conversion;
  79.         }
  80.  
  81.     </script>
  82.    
  83. </body>
  84. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement