Question

Please help me with the following requirements for JavaScript. Write a function to take a temperature value in Celsius a...

Please help me with the following requirements for JavaScript.

Write a function to take a temperature value in Celsius as an argument and return the equivalent temperature in Fahrenheit, basing it on the code from Hour 2.

//Original Code

<!DOCTYPE html>
<html>
<head>
    <title>Fahrenheit From Celsius</title>
</head>
<body>
    <script>
        var cTemp = 100;  // temperature in Celsius

        var hTemp = ((cTemp * 9) /5 ) + 32;
        document.write("Temperature in Celsius: " + cTemp + "
degrees<br/>");
        document.write("Temperature in Fahrenheit: " + hTemp + "
degrees");
    </script>
</body>
</html>

//My Code

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Celsius To Fahrenhiet</title>

</head>

<body>

<script>

function celsiusToFahrenheit(celsius) {

var celsius = 100;

var fahrenheit = ((celsius * 9) /5) + 32;

}

</script>

<script>document.write("It is " + celsius + " degrees Celsius")</script>

<br/>

<script>document.write("In Fahrenheit it is " + fahrenheit + " degrees");</script>

</body>

</html>

I am having issues making it run correct, I need to use the original code, can I get help please.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here need to send celsius as an argument and we get fahrenheit as return value for the function celsiusToFahrenheit() when called. I code you wrote, you are not calling the function to get result. So, here I attach the modified code. Hoping it helps.

Please comment for further assistance.

<html>
<!DOCTYPE html>
<head>

<meta charset="UTF-8">

<title>Celsius To Fahrenhiet</title>

</head>

<body>

<script>

function celsiusToFahrenheit(celsius) {
var fahrenheit = ((celsius * 9) /5) + 32;
return fahrenheit;
}

cel = 100;
document.write("It is " + cel + " degrees Celsius<br/>")
document.write("In Fahrenheit it is " + celsiusToFahrenheit(cel) + " degrees");
</script>  
</body>

</html>

Add a comment
Know the answer?
Add Answer to:
Please help me with the following requirements for JavaScript. Write a function to take a temperature value in Celsius a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • could you please show me what I am doing wrong in the Javascript code below. <html>...

    could you please show me what I am doing wrong in the Javascript code below. <html>   <head> <meta charset="UTF-8"> <title></title> <style> #mytext { color: white; text-align: center; } </style> <script> var words = "The cat sat on the mat"; document.writeln("id='mytext"+ words '); </script>   </head>   <body>   </body> </html>

  • Javascript + HTML, no JQuery please. So, Im trying to figure out how to send an...

    Javascript + HTML, no JQuery please. So, Im trying to figure out how to send an alert if the value of my selection is "0". I will be using this for a validation form assignement. So if the user leaves the selection on the default "0" value I can prompt the user to pick a valid option which would be 1+. Not sure how to access this value. Example code below: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Form Validation</title>...

  • Javascript program reformation A. combine three loops into one loop and REPLACE FOR LOOP with a...

    Javascript program reformation A. combine three loops into one loop and REPLACE FOR LOOP with a while loop to maintain the same result <!DOCTYPE html> <html><head><title>19.7 For Loop</title> <script language="javascript"> //numbers divisible by 5 for (i=1; i<=50; i++) {    if (i%5 == 0) document.write ("number divisible by five is: " + i + "<br />"); } //for document.write ("========================<br />"); //separator //odd numbers divisible by 7 for (i=1; i<=50; i++) {    if ((i%7==0) && (i%2!=0)) document.write ("odd number...

  • In an external JavaScript file, you need to create two global variables for the Quarter name...

    In an external JavaScript file, you need to create two global variables for the Quarter name array and the Sales amount array. Create an anonymous function and connect it to the onclick event of the Add to Array button that adds the values from the fields (Quarter and Sales) to the respective arrays. Create an anonymous function and connect it to the onclick event of Display Sales button displays the contents of the arrays, displays the sum of all the...

  • In this Javascript code, why are 2 for loops needed? could you please explain this to...

    In this Javascript code, why are 2 for loops needed? could you please explain this to me. This is the outcome * ** *** **** ***** ****** ******* ******** ********* the code is <html> <head>               <title></title>        <script>                  showStars(10);               function showStars(rows){            for(var i = 0; i < rows; i++){                var pattern = "";                for(var j...

  • use the sample html file below with a submit button to modify the style of the...

    use the sample html file below with a submit button to modify the style of the paragraph text through JavaScript code. By clicking on the button, the font, the font size, and the color of the paragraph text will be changed. <!DOCTYPE html> ·         <html> ·         <head> ·         <meta charset=utf-8 /> ·         <title>Change Paragraph Text</title> ·         </head>   ·         <body> ·         <p id ='text'>I’m going to change this text, I hope.</p>   ·         <div> ·         <button id="jschange" ·         onclick="js_style()">Style</button> ·         </div> ·         </body> ·         </html>

  • Please help me with this code for javascript. <!DOCTYPE html> <html> <head> <title>Strings and Arrays</title> <script>...

    Please help me with this code for javascript. <!DOCTYPE html> <html> <head> <title>Strings and Arrays</title> <script> function wrangleArray() { var string1 = prompt("Enter: This class is going to fast");//Must be entered by the user var string1 = "";//Is this right? I want that string to change later by a series of prompt questions document.getElementById("div1").innerHTML = "<p>" + sentence + "</p>"; var words = sentence.split(" ");//I need to convert my string to an Array is this the way to do it?...

  • in the following java script code follow the instructions provided <!DOCTYPE html> <html> <head> <!-- JavaScript...

    in the following java script code follow the instructions provided <!DOCTYPE html> <html> <head> <!-- JavaScript 6th Edition Chapter 5 Hands-on Project 5-2 Author: Date:    Filename: index.htm --> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Hands-on Project 5-2</title> <link rel="stylesheet" href="styles.css" /> <script src="modernizr.custom.05819.js"></script> </head> <body> <header> <h1> Hands-on Project 5-2 </h1> </header> <article> <h2>Change of address form</h2> <form> <fieldset id="contactinfo"> <label for="addrinput"> Street Address </label> <input type="text" id="addrinput" name="Address" /> <label for="cityinput"> City </label> <input type="text" id="cityinput" name="City"...

  • Using Javascript, I have two radio buttons, depending on the value of the radio button 1...

    Using Javascript, I have two radio buttons, depending on the value of the radio button 1 or 2, you will send a different form to the user. So, if radio button is value "1" send new form1 or if value "2" send new form 2.  New form will ask for letter grades for four courses in textboxes. Onsubmit of new form letter grades A,B,C,D need to be changed to numeric values 1,2,3,4 so an average grade for the four couses can...

  • I am trying to make it so that radio buttons when clicked execute a javascript file....

    I am trying to make it so that radio buttons when clicked execute a javascript file. I have to to have the exercises in external files. Here is what I have so far. I am reusing a script that was used to make radio buttons switch CSS files so I think I have to change the set attribute options. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <p> 4.2 Output: The first 20 Fibonacci numbers, which are...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT