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>...

  • The code below modifies the CSS style on button click. Give the output of the code...

    The code below modifies the CSS style on button click. Give the output of the code and modify the code such that background color of title should also be modified . <!DOCTYPE html> <html lang="en"> <head> <title>JavaScript and HTML</title> <meta charset="utf-8"/> <style> h1 { color:blue; background-color:lightGreen; border:12px solid green; padding: 5px; border-radius: 15px; text-align: center; } p, h1 { } } </style> <script> function changeTitleCSSStyle() { var title = document.querySelector("#mainTitle"); title.style.color = 'black'; title.style.border = "5px dashed red"; } </script>...

  • 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...

  • Write a PHP Script containing a function that calculates the tax (8%) on a purchase of...

    Write a PHP Script containing a function that calculates the tax (8%) on a purchase of $48.72. What I have so far. index.html <!DOCTYPE html> <html lang="en"> <head> <title>PHP Lab II</title> <meta charset="utf-8"> <link rel="stylesheet" href="main.css"> <meta name="robots" content="noindex, no follow, noarchive" /> <meta name="author" content="Michael Dimond Jr" /> </head> <body> <div id="wrapper"> <header> <h1>PHP Lab II</h1> </header> <main> <form action="display.php" method="post">    <div>        <label>Sale Total: </label>        <input type="text" name="sale_total"><br>        <br>    </div>   ...

  • 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...

  • This is an HTML and javascript code that I tried to replicate form this video but...

    This is an HTML and javascript code that I tried to replicate form this video but it wouldn't work for me for some reason can you help me fix this issue. thanks, https://youtu.be/F7C30e7gR2Y <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>cicle Animation in js</title> <style> body { height: auto; margin: 0; } #ocean { position: absolute; width: 100%; min-height: 100%; background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0, 50, 150)), color-stop(0.50, rgb(0, 150, 255)); } .wave { background: blue ; display:...

  • 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?...

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