My Practice Question
My Practice Question
JavaScript Fundamentals
a) Explain the differences between internal and external JavaScript with suitable examples. (5
marks)
b) Write a JavaScript program that uses loops and arrays to compute the average of five
numbers entered by the user. (5 marks)
VTU question
a) Describe the use of if, else, and switch statements in JavaScript with examples.
b) Write a JavaScript program using a loop (for or while) to display the multiplication table of a
given number.
a) Explain how to declare, initialize, and access arrays in JavaScript. Provide examples.
b) Demonstrate string manipulation using built-in methods like substring(), toUpperCase(), and
split().
a) What are JavaScript events? Explain how to handle events with examples.
b) Write a program to change the background color of a webpage when a user clicks a button.
Q10. Drawing 2D Shapes
a) Explain how to use the <canvas> element in HTML and draw using JavaScript.
b) Write JavaScript code to draw a rectangle and a filled circle on the canvas.
Q3. Components
a) How do you read and update the state in a class and functional component (using hooks)?
b) Write an example component that increments a counter on button click.
a) List and explain any five best practices to write efficient ReactJS code.
b) How does conditional rendering help in performance optimization?
Create a ReactJS application where a navigation bar contains buttons like "Home", "About", and
"Contact". Clicking each button should dynamically render the respective component without
reloading the page. Explain the logic behind component-based rendering.
Build a React component that fetches data from a mock API (e.g., JSONPlaceholder) and
displays it in a list. Use useEffect hook to fetch the data. Explain how lifecycle management is
handled in both class and functional components.
Design a registration form in React that includes name, email, and password fields. Add custom
validation such that:
Create a parent component that holds a list of tasks and two child components: one for adding
tasks, and one for displaying them. Use state lifting to manage shared data across components.
Explain how you structured the data flow.
Q5. Custom Hooks
Write a custom React hook called useCounter that provides count, increment, and decrement
functions. Then use this hook in a component. Explain the benefits of custom hooks in code
modularity.
Build a React component that displays a product catalog with a "View Details" button. Clicking
the button should expand the product card to show additional info (price, description). Use
conditional rendering to implement this and explain the logic.
Create a React app with multiple child components. Implement React.memo() and the
useCallback hook to avoid unnecessary re-renders when props or state do not change.
Demonstrate with performance profiling and justify each optimization.
Integrate react-router-dom into a ReactJS application with at least three pages: Home, Profile,
and Settings. Use dynamic routing for user profiles like /profile/:userid. Show how navigation
and URL parameters are handled.
Create a React+Redux app that fetches and displays a list of posts from an API. Use redux-thunk
or redux-saga to manage async actions. Write the full Redux cycle: actions, reducers, store
configuration, and component connection.
Implement an error boundary component in React that catches runtime errors in child
components and displays a fallback UI. Demonstrate with a component that intentionally
throws an error. Explain when and why error boundaries are used.
• Date selectors
Develop a web-based dashboard layout using CSS Grid for structure and Flexbox for internal
alignment. Include widgets for weather, news, and stocks. Explain where and why you chose
each layout model.
Build a multi-sectioned webpage (like an article page) and apply ARIA roles, semantic HTML,
proper tab order, and alt text for images. Demonstrate how it improves accessibility for screen
readers and keyboard navigation.
Create a responsive, animated navigation bar using pure HTML and CSS that includes:
Build a photo gallery with image overlays and modal previews using only CSS. On hover, show
image titles; on click, zoom into an image with an animated modal. No JavaScript allowed.
Justify your choice of techniques.
Q7. CSS Animations and Transitions
• Row/column spans
Create a form that collects product details (name, quantity, price) and use HTML/CSS to format
the output as an invoice (on submission). The styling should closely resemble a printed bill.
Explain how CSS pseudo-elements enhance styling.
Develop a video blog layout using the HTML5 <video> and <audio> tags:
6. How can you access the value of a text input field with ID userName?
7. Write the syntax to create an array of 5 numbers.
10. Write one line of code to change the inner text of an element with ID message.
4. Mention one key difference between ReactJS and vanilla JavaScript DOM manipulation.
5. How can you pass data from a parent to a child component in React?