Suffyan WEB Assignment 2
Suffyan WEB Assignment 2
<head>
<title>Finding Errors</title>
</head>
<script type="text/javascript"
document.writeln("Two, ")
</script>
</body>
</html>
Answer:
<html>
<head>
<title>Finding Errors</title>
</head>
</script>
</body>
</html>
Question 2: How would you concatenate the following three strings with
JavaScript
Answer:
<html>
<head>
<title>Concatenation</title>
<script type="text/javascript">
function concate()
var a="trans";
var b="por";
var c="tation";
var d=a+b+c;
</script>
</head>
<body>
<p>por</p>
<p>tation</p>
</body>
</html>
Answer :
<html>
<head>
</head>
<body>
<script type="text/javascript">
var a="aslam";
var b="ali";
var c="bai";
document.write (a+b+c);
</script>
</body>
</html>
Question.4. Create a JavaScript program that will print “Hello, world! Isn’t
life great?” in an Arial bold font, size 14, and make the background color of
the screen light green.
Answer:
<html>
<head>
</head>
<body id=”back”>
<script>
var a=document.getElementById(“back”);
a.style.background=”lightgreen”;
var b=document.getElementById(“p”);
b.style.fontFamily=”Arial”;
b.style.fontSize=”14px”;
</script>
</body>
</html>
Question 5: Add two strings to the first JavaScript program—your first name
and last name—concatenated and printed in a blue sans serif font, size 12.
Answer:
<html>
<head>
<title>question 5</title>
</head>
<script>
var a="suffyan";
var b="Arshad";
</script>
</body>
</html>
Answer:
<html>
<head>
<title>question 6</title>
<script>
function op(a,b,c)
return X+Y+Z/5;
</script>
</head>
<body>
<script>
var m=op(a,b,c);
</script>
</body>
</html>
Alert(“hello”,”world!”);
Answer : The word (hello) is just shown in the alert box .Because syntax of alert box just
exceute just first doble quotes.
Answer :
<html>
<title>question 8</title>
<head>
<script>
function f()
alert("ASLAM U ALIKUM");
</script>
</head>
<body>
<form>
</form>
</body>
</html>
Question 9: Write a script that contains four variables in the head of the
document: The first one contains your name, the second contains the value 0,
the third one is declared but has no value, and the last contains an empty
string. In the body of the document, write another script to display the type of
each (use the typeof operator).
Answer:
<html>
<head>
var a=”name”
var b=0;
var c;
var d=” ”;
</script>
</head>
<body>
<script>
document.write(typeof a);
document.write(typeof b);
document.write(typeof c)
document.write(typeof d);
</script>
</body>
</html>
Question 10: What is the return value of the prompt method if the user
doesn’t enter anything? Where is the return value stored?
Answer: If user doesn’t enter anything and press ok button then prompt return nothing. If
prompt show highlighted value in the prompt and user doesn’t enter anything and press ok
button then prompt return highlighted text. If user doesn’t enter anything or enter some value in
prompt and press cancel button then prompt return null value.The return value of prompt stored
in the variable for which we use prompt.
Question 11: Create a JavaScript program that prompts the user for a phone number and
then asks the user for confirmation.
Answer:
<html>
<head>
</head>
<body>
<script>
if(con==true)
else
</script>
</body>
</html>
Question 12: Write a function that will calculate and return the amount that
should be paid as a tip for a restaurant bill. The tip will be 20 percent of the
total bill.
Answer:
<html>
<head>
function cal( t)
var tp=20/100*a;
return tp;
</script>
</head>
<body>
<script>
</script>
</body>
</html>
Question 13: Create a function called changeColor () that will be called when
the user presses one of two buttons. The first button will contain the text
“Press here for a yellow background”. The second button will contain the text
“Press here for a light green background”. The function will take one
parameter, a color. Its function is to change the background color of the
current document; for example, bgColor=“yellow”.
Answer:
<html >
<head>
<script>
function changeColor(a)
document.body.style.background=a;
</script>
</head>
<body>
</body>
</html>
Question 14: Write a function that returns the total cost of any number of
buckets of paint. Ask the user how many buckets he or she is going to buy and
for the cost of one bucket. Ask the user the color of the paint. Calculate and
return what he or she owes. Change the color of the font to the color of the
paint. Use the catch/try/throw statements to check for invalid input if the user
doesn’t give you a valid value for the number of buckets, such as a number
less than 0, or gives you no input, or types in a string, and so on, check that
the user doesn’t give you a color of paint that is the same color as the
background of your document or you will not be able to see the color of the
font.
Answer:
<html >
<head>
</head>
<body>
<script>
function Total(b,p,c)
totalcost=b*p;
var str = new String("same as the color you enter is dialog ");
document.write(str.fontcolor(color));
try {
x = Number(x);
catch(err) {
</script>
</body>
</html>