Tutorial J3: Name: Tan Wan Sean Date: 29 May 2020
Tutorial J3: Name: Tan Wan Sean Date: 29 May 2020
1. Open a text editor of your choice, such as Notepad (on Windows) or TextEdit (on a Mac).
2. Create an HTML page leaving space between <body> and </body> tags.
3. Between the <body> and </body> tags add the <script> and </script> tags.
4. Create a function named car_cost() that takes two arguments, mycar and paycheck.
5. Create a window.alert() command that will display an alert with the following message:
“You have a <mycar variable here> and make $<paycheck variable here>”
6. Create a function named get_added_text() that returns the value of two strings added
together inside the function. The two strings to add are these two separate strings:
function get_added_text()
{
var textpart1 = "This project ";
var textpart2 = "is almost fun!";
var addedtext = textpart1 + textpart2;
return addedtext;
}
8. In the main script (after the function definitions), call the car_cost() function, and send it the
values of “Proton” and 3500 as arguments.
car_cost("Proton", 3500);
9. In the main script (after the function definitions), assign the result of the get_added_text()
function to a variable named alerttext. Create an alert that pops up with the value of that
variable.
var alerttext=get_added_text();
window.alert(alerttext);
10. Save the file and execute it. When you open the Web page, you should see two alert messages:
11. Which line calls the first window and which line calls the second window?.
window.alert("You have a "+ mycar + " and make $" + paycheck);
}
__________________________________________________________________________
var alerttext=get_added_text();
window.alert(alerttext);
__________________________________________________________________________
15. Try the code below. The getElementById() method returns the element that has the ID attribute
with the specified value. The program multiplies a=4 and b=3.
16. Using the above code write a program to get the radius of a circle and use a function to calculate
the circumference and the area of the circle.
17. Using the above code write a program to convert Fahrenheit to Celsius. The formula is
C = (F-32) * 5/9. Validate your program to check if 212F is converted to 100C. Show your code
below:
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
function toCelsius(f){
return (5/9)*(f-32);
document.getElementById("demo").innerHTML=toCelsius(212);
</script>
</body>
</html>