0% found this document useful (0 votes)
105 views1 page

JavaScript Practical Exam Questions

The document lists practical exam questions focused on JavaScript programming tasks. It includes exercises on basic arithmetic operations, prime number checking, Fibonacci series generation, array manipulations, string operations, form validations, and user interface interactions. Additionally, it covers cookie management, window manipulation, and creating dynamic web elements.

Uploaded by

Kshitija Khilari
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
105 views1 page

JavaScript Practical Exam Questions

The document lists practical exam questions focused on JavaScript programming tasks. It includes exercises on basic arithmetic operations, prime number checking, Fibonacci series generation, array manipulations, string operations, form validations, and user interface interactions. Additionally, it covers cookie management, window manipulation, and creating dynamic web elements.

Uploaded by

Kshitija Khilari
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Practical Exam Questions

1. Write a JavaScript program to calculate add, sub, multiplication and division of two number (input
from user). Form should contain two text boxes to input numbers and four buttons for addition,
subtraction, multiplication and division.
2. Write a JavaScript program to check whether entered number is prime or not.
3. Write a JavaScript function to generate Fibonacci series till user defined limit.
4. Write a JavaScript program to calculate the factorial of a number using a looping statement.
5. Develop a JavaScript program to sort an array of numbers in ascending order.
6. Create a JavaScript program to find the sum of all elements in an array.
7. Create a program to find the largest and smallest numbers in an array.
8. Write a JavaScript function that checks whether string is palindrome or not, accept string from user
and pass it as an argument to the function.
9. Write a JavaScript that takes a String as input and performs the following operations on String:
• Convert the sentence to lowercase.
• Remove any extra spaces at the beginning or end of the sentence.
• Split the sentence into an array of words.
10. Create a Student Registration Form using HTML and JavaScript. Validate fields such as:
• Name: Only alphabets allowed.
• Email: Must include @ and .com.
• Age: Must be between 18 and 30.

11. Design an Employee Registration Form and validate the following:


• Employee ID: Must be exactly 5 digits.
• Phone Number: Validate for 10 digits only.
• Department: Should not be blank.

12. Design a Form and Accept name, email and pin code(number only) from user in a form, where
• Name, Email, Pin code should not be blank
• Pen code must be 6 digits long
13. Develop a Program to replace submit and reset button with image Using Intrinsic Function.
14. Create a webpage with a button to set a cookie that expires after 7 days. Display a message
indicating when the cookie will expire. Accept name and value of cookie from user.
15. Develop a webpage where clicking a button opens a child window displaying "Welcome to the
Window Practical”, with a custom size (e.g., 400x400 pixels) and title "Child Window".
16. Create a webpage with two buttons: one to open a child window with message “Child window is
opened” , and another to close the child window show alert when closed.
17. Write a JavaScript program to validate email ID, Phone Number of the user using regular
expression.
18. Write a JavaScript to create Rollover effect, where font colour or background colour of text changes
when user rolls over(hover) the text(display multiple fruit names).
19. Write a JavaScript to create a pull – down menu with four options [AICTE, DTE, MSBTE,
GOOGLE]. Once the user will select one of the options then user will be redirected to that site.
20. Write a JavaScript to create and display banner on webpage loading, banner will be removed
automatically after 5 seconds of webpage loading.

Common questions

Powered by AI

To generate a Fibonacci series in JavaScript up to a user-defined limit: 1. Accept the limit input from the user. 2. Initialize the first two Fibonacci numbers, typically 0 and 1. 3. Use a loop to calculate subsequent Fibonacci numbers by adding the two preceding numbers. 4. Continue the loop until the generated numbers exceed the user-defined limit. 5. Store and return the Fibonacci sequence as an array. This iterative approach efficiently generates the series up to the specified number .

To design a JavaScript application implementing an image rollover effect: 1. Create HTML elements displaying images or text that will change upon user interaction. 2. Use CSS to define the initial and hover states, such as changing background or text color. 3. Use JavaScript to add event listeners for 'mouseover' and 'mouseout' events on the target elements. 4. Within the event listeners, change the style properties to implement the desired effects. This approach provides a dynamic and visually engaging user interaction .

Using JavaScript to manage cookies for state persistence provides benefits such as storing user preferences, session data across pages, and maintaining continuity in user experience. However, challenges include security risks like exposure to XSS attacks, limited storage space, and browser variations in cookie handling. Cookie expiration needs careful handling to ensure data manageability and compliance with privacy laws. JavaScript provides functions like 'document.cookie' to set and manage cookies, where proper encoding of data is crucial for security .

To create an email validation program using JavaScript and regular expressions: 1. Obtain the email input from the user via an HTML form. 2. Define a regular expression pattern to match standard email formats. A typical pattern would be /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/ 3. Use JavaScript's 'test()' method to verify the input string against the regex pattern. 4. Provide feedback to the user based on the test result. This method ensures robust client-side email validation by checking common structural rules for email addresses .

To redirect a user based on a pull-down menu selection with JavaScript: 1. Create an HTML select element with various options, each having a value associated with the target URL. 2. Attach an 'onchange' event listener to the select element. 3. Use the 'window.location.replace()' method inside the event handler to redirect the user to the URL corresponding to the selected option. This technique enables seamless navigation and is particularly useful in web applications requiring dynamic page changes .

When designing a JavaScript program to open a child window, consider the window size, title, and browser compatibility. Use the 'window.open()' method with parameters specifying dimensions and window features. Ensure the size fits the content and doesn't overflow screen boundaries. Titles should be descriptive but concise, aiding in user context-switching. Account for pop-up blockers by ensuring the action is user-initiated. Consider layout and interaction to enhance user experience while adhering to security best practices to prevent window manipulation by malicious scripts .

To create a JavaScript program that checks if a number is prime: 1. Get the number input from the user. 2. Validate the input to ensure it is a positive integer. 3. Implement a function that iterates from 2 to the square root of the number, checking divisibility. 4. If divisible by any number within this range, it's not prime. 5. If no divisors are found, the number is prime. This approach optimizes by reducing unnecessary checks beyond the square root of the number .

To sort an array of numbers in ascending order using JavaScript: 1. Accept input array from the user. 2. Utilize the JavaScript array method 'sort()'. 3. Pass a comparison function to 'sort()' that subtracts the current element from the next element. This comparison function correctly handles numerical sorting, as the default sort implementation treats elements as strings, leading to correct ascending order. This approach efficiently organizes the array without external libraries .

To implement a JavaScript palindrome checker: 1. Accept a string input from the user. 2. Remove non-alphanumeric characters and convert the string to lowercase for uniformity. 3. Reverse the processed string using JavaScript's string functions and compare it to the original processed string. 4. If they match, the input is a palindrome; otherwise, it isn't. This function leverages JavaScript's built-in capabilities to manipulate and compare strings efficiently .

JavaScript can be used for client-side form validation by attaching event listeners to the form's submit event. For a Student Registration Form: 1. Validate the name to ensure it contains only alphabets using regex (/^[A-Za-z]+$/). 2. Check the email format to include an '@' symbol and a domain such as '.com' using regex (/^[\w\.-]+@[\w\.-]+\.com$/). 3. Ensure age is within a specified range (18 to 30 years) by converting and checking the value numerically. This real-time validation prevents incorrect data submission and enhances user experience by providing immediate feedback .

You might also like