You are on page 1of 6

Q1) Is java and java script both are similar? Write the difference between both of them.

Ans 1: According to the Java platform official website, the main difference between Java and JavaScript is that Java is
an OOP programming language while JavaScript is an OOP programming script. JavaScript code is written
completely in text and need only be interpreted. Java, on the other hand, must be compiled.
Q2) Point the errors in the following code and write the corrected script:

<SCRIPT LANG="JavaScript"> -- <script type=”text/javascript”>


var A=10;
var B=6;
switch A%B--- switch(A%B)
{
case 0;
document.write("The input is:");
break;
case 1;
document.write("The colour is:")
break;--- break will not come
else;
document.write("You didn't choose")
}
</SCRIPT>

Q3 How the forms are handled in JavaScript? Explain

Ans: Forms are an extremely important part of HTML and the Web Platform. They allow

users can interact with the page and search something on the site , trigger filters to trim
result pages send information and much much more. The main one being that a JavaScript
form relies on one or more event handlers, such as onClick or onSubmit. These invoke a
JavaScript action when the user does something in the form, like clicking a button.

By default, forms submit their content to a server-side endpoint, which by default is the
page URL itself:
Q4. How can JavaScript make a website easier to use? That is, are there certain
JavaScript techniques that make it easier for people to use a website?

Ans :JavaScript's greatest potential gift to a Web site is that scripts can make the page more
immediately interactive, that is, interactive without having to submit every little thing to the
server for a server program to re-render the page and send it back to the client.

For example, consider a top-level navigation panel that has, say, six primary image map
links into subsections of the Web site.
With only a little bit of scripting, each map area can be instructed to pop up a more detailed
list of links to the contents within a subsection whenever the user rolls the cursor atop a
map area. With the help of that popup list of links, the user with a scriptable browser can
bypass one intermediate menu page.

The user without a scriptable browser (or who has disabled JavaScript) will have to drill
down through a more traditional and time-consuming path to the desired content.

Q5. How do you convert numbers between different bases in JavaScript?

Ans : parseInt() The parseInt() function parses a string argument and returns an integer of the
specified radix (the base in mathematical numeral systems).
The main purpose of using the parseInt function is to extract a number from a string. This turns the
returned value to an actual number.
To convert numbers between different bases in JavaScript, we can use the parseInt function.
For instance, we write
const n = parseInt(string, radix)
to call parseInt to convert the number string into the base specified by the radix.

Conclusion

To convert numbers between different bases in JavaScript, we can use the parseInt function.
Another answer
 Example:

<script>

var v1 = parseInt("3.14");

document.write('Using parseInt("3.14") = '

+ v1 + "<br>");

</script>

 Output:
Using parseInt("3.14") = 3

The parseInt() function is used to accept the string ,radix parameter and convert it into an
integer.The radix parameter is used to specify which numeral system to be used, for example, a
radix of 16 (hexadecimal) indicates that the number in the string should be parsed from a
hexadecimal number to a decimal number. If the string does not contain a numeric value then it
returns NaN i.e, not a number.
Syntax:
parseInt(Value, radix)
Parameters: This function accepts two parameters as mentioned above and described below:
 Value: This parameter contains a string which is converted to an integer.
 radix: This parameter represents the radix or base to be used and it is optional.
Return value: It returns a number and if the first character can’t be converted to a number then the
function returns NaN. It actually returns a number parsed up to that point where it encounters a
character that is not a number in the specified radix(base)

Q6. How do we get JavaScript on a web page explain?

Ans :
Using the <script> tag, you can add a short script (in this case, just one line) to a web document, The <script> tag tells
the browser to start treating the text as a script, and the closing </script> tag tells the browser to return to HTML mode. In
most cases, you can’t use JavaScript statements in an HTML document except within <script> tags.

The HTML and CSS are put together by the DOM to create the web page first. Then, the browsers' JavaScript engine
loads JavaScript files and inline code but does not run the code immediately. It waits for the HTML and CSS to finish
loading. Once this is done, the JavaScript is executed in the order the code is written.

Following are some common attribute of <script> tag


src: It defines the address of the external file which can be absolute or relative URL
type: Define the MIME-type of the script.
charset: Define the character encoding of the external JavaScript file.

There are four different place in the HTML document where scripts can be used.
1. Body of the page: In this case when page is loaded in the browser then output is displayed as the part of the HTML
document.
2. Header of the page: In this case code is written in the form of function (groups of JavaScript statement but treated as
single unit) and referred in the other script in the same page.
3. Within HTML tag: When JavaScript is used as a event handler (will be discussed later) then it work with HTML
elements.
4. As external file: In this case JavaScript code is written in another file having .js extension. This file is included in a
script tag by specifying the file name.
<html>
<head>
<title>My Javascript Page</title>
</head> <body>
<script type=“text/javascript”> document.write("Hello"); (“Welcome to my world!!!”);
</script>
</body>
</html>
Q.7 Write a program in JavaScript using various data types to find the round off integer
values?
Ans : <html>
<body>

<h2>JavaScript Math</h2>

<p>Math.round() rounds a number to the nearest integer:</p>

<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML = Math.round(2.5);
</script>

</body>
</html>

Q8. Write the program in JavaScript to solve the given polynomial:


x3 + 2x2.y + 3x.y2 + y3 = 0

Q9. Design a home page of your school. Include some images/pictures and other events
of an academic calendar for session 2013-2014. Also include some audio/video
features to make your web-site more interactive.

You might also like