Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have included what direction I have and I have also included all the files that are needed for this program. It is a program

I have included what direction I have and I have also included all the files that are needed for this program. It is a program using JavaScript. I am needing the code that goes where it says //Create the code needed here, under the Chapter7.js file.

We will be creating a simple temperature conversion calculator. It will take an input temperature and convert it to either celcius or fahrenheit. Since this chapter is about creating functions, I have created the inital function that will trigger when the button is clicked, along with 2 sample function calls in an if statement that is checking which radio button is selected. You can either use these names or change them to match whatever you call your functions.

You will need 2 functions. 1 of them for converting from F to C and one for converting C to F. You will need to display the calculated temperature in the output div called divResults. You can use the function I have already created for reference to help you. Remember that when working with numbers out of a text box you need to tell JavaScript to treat them as numbers using parseInt or parseFloat, but in this situation we shouldn't be entering decimal points so parseInt is acceptable. The formulas for conversion are listed below:

Fahrenheit to Celcius C = (F - 32) * (5 / 9)

Celcius to Fahrenheit F = (C * (9 / 5)) + 32 I have also placed a comment section in the .js file that contains the formulas for quick reference while you work. If you run into trouble, please let me know.

Chapter7.css

body{

margin:0;

background:#333;

}

.main{

width:400px;

height:auto;

background:#fff;

margin:50px auto;

text-align:center;

padding: 25px 0;

}

.main input{

margin:25px 0;

}

Chapter7.html

Chapter 7 Temperature Converter

Temperature Converter

Enter a Temperature to Convert in the field below and select the starting scale.



Fahrenheit to Celcius



Celcius to Fahrenheit







Chapter7.js

// COURSE: CIT 140 JavaScript

// NAME:

// DATE:

// PROJECT: Chapter 7 Programming Project

function ConvertTemp(){

var radF = document.getElementById('radFahrenheit');

var radC = document.getElementById('radCelcius');

if(radF.checked){

//Call Function to Convert F to C

FahrenheitToCelcius();

}else if(radC.checked){

//Call Function to Convert C to F

CelciustoFahrenheit();

}

}

//Create your Conversion Functions Below

/* FORUMULAS

*

* Fahrenheit to Celcius

* C = (F - 32) * (5 / 9)

*

* Celcius to Fahrenheit

* F = (C * (9 / 5)) + 32

*/

//Create the code needed here.

//This is the event handler for the button.

function init() {

//Assign the HTML element to a JavaScript variable called btnConvert

var btnConvert = document.getElementById('btnConvert');

//Set the ConvertTemp function above to the onclick event of the button Variable

btnConvert.onclick = ConvertTemp;

}

//Run the INIT function when the page finishes loading.

window.onload = init;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions