JSFiddle - React, Tailwind, and code Playground

by Jordan Marechal

JavaScript

var convertCtoF = document.getElementById("degC");
 convertCtoF.onchange = function(){  //onchange means that every time the value in the input box changes, this function will run
                var degreesC = document.getElementById("degC").value; // this is the value from the form field
                var degC = (degreesF-32) * (5/9);
                 
              document.getElementById("degC").value=degC;
        
                // your calculations go here. You'll start with the variable degreesC, convert it to Fahrenheit
                //  and place the result in the variable 'degreesF'
                var degreesF = (degC * 9/5 + 32); 
                 
                    return degreesF;// you will set this to the results of your conversion

                // now we write the result to the page
                document.getElementById("degFOut").innerHTML = degreesF;
 }

 var convertFtoC = document.getElementById("degF");
 convertFtoC.onchange = function(){  //onchange means that every time the value in the input box changes, this function will run
                var degreesF = document.getElementById("degF").value; // this is the value from the form field
                var degF = degC= 5/9*(degF-32);
               
                document.getElementById("degF").value=degF;

                // your calculations go here. You'll start with the variable degreesF, convert it to Celsius
                //  and place the result in the variable 'degreesC'
                var degreesC = (degreesF- 32) * (5/9);
                    
                        return degreesC;// you will set this to the results of your conversion


                // now we write the result to the page
                document.getElementById("degCOut").innerHTML = degreesC;
 }