CS101 Assignment 3 Solution
#1

CS101 - Introduction to Computing
Assignment 3 - Spring 2017

Problem Statement: Create a Temperature Converter webpage with only HTML and JavaScript. It must convert user entered value from Fahrenheit to Celsius and vice versa.  Output must be an Integer and you must not use Math.round() function. There should not be a button, but a statement that shows whether the user has selected Fahrenheit or Celsius for conversion from the drop down list. 
Screenshots are given in the assignment file.

Solution:
Copy the following code and paste it in the notepad in your computer, only use notpad and not wordpad or Microsoft Word. Click on File option and then Save the file with extension .html e.g. yourname.html 
Code:
<html>
<head>
<title>Student Id: "Write your student ID here"</title>
</head>
<body>
<h1>Convert temprature</h1>
<table>
    <tr>
        <td>Enter a value:</td>
        <td><input type="text" onChange="myFunction()" name="uvalue" id="uvalue"></td>
        <td>
            <select name="utype" id="utype" onChange="myFunction()">
                <option value="b">Fahrenheit (F&deg;)</option>
                <option value="a">Celsius (C&deg;)</option>
            </select>
        </td>
    </tr>
    <tr>
        <td>Answer:</td>
        <td><input type="text" name="answer" id="answer"></td>
    </tr>
    <tr>
        <td></td>
        <td colspan="2"><p id="bottomline"></p></td>
        <script>
        function myFunction()    {
    var w;
    var x = document.getElementById('uvalue').value;
    var y = document.getElementById('utype').value;
    function RoundNum(number){
   var a = number % 1;
   return number-a+(a/1+1.5>>1)*1
}

        if(y == "a"){
            document.getElementById('bottomline').innerHTML = "You Selected: Celsius to Fahrenheit";
            w = x * 9 / 5 + 32;
            document.getElementById('answer').value =  RoundNum(w);
        }
        if(y == "b"){
            document.getElementById('bottomline').innerHTML = "You Selected: Fahrenheit to Celsius";
            w = (x -32) * 5 / 9;
            document.getElementById('answer').value =  RoundNum(w);
        }
    }
    
</script>
    </tr>
</table>
</body>
</html>

Write your Student ID in the title tag where suggested. 
Remember to save the file with .html extension.
Reply
#2

Thank u soooooooooo much Rana
Reply
#3

(07-08-2017, 07:58 PM)Khadija Wrote:  Thank u soooooooooo much Rana

You're welcome. And do make sure to change the assignment and do not only copy/paste as it is. Or you will be graded ZERO marks.
Reply
#4

http://buytadalafshop.com/ - cialis online
Reply
#5

http://buysildenshop.com/ - Viagra
Reply
#6

https://buytadalafshop.com/ - best place to buy cialis online
Reply
#7

http://buysildenshop.com/ - Viagra
Reply
#8

http://buytadalafshop.com/ - buy generic cialis online
Reply
#9

https://buysildenshop.com/ - Viagra
Reply
#10

http://buytadalafshop.com/ - cialis online cheap
Reply


Possibly Related Threads…
Thread / Author Replies Views Last Post
Last Post by othesia
09-25-2021, 06:04 AM
Last Post by Crywoge
09-22-2021, 01:53 AM



Users browsing this thread: 1 Guest(s)