JavaScript Tasks for Beginners
Aim: Study and Understand and Execute the code for the following tasks.
Imagine you are starting up a company or startup - so you need a website - and think about these
tasks where you can make use of them. Don't simply copy-paste anything; think and create
functions according to the requirements that your website will have. At last, add print() to save or
print your entire page into a PDF.
Task 1
Define Variables in JavaScript
- Declare variables using var, let, and const.
- Assign values to variables and display them using console.log().
Task 2
Create Basic Functions in JavaScript
- Define a function using function keyword and call it.
- Create arrow functions and understand the syntax.
- Use functions to perform simple mathematical operations like addition and subtraction.
Task 3
Use Built-in Functions
- Use alert() to display a message to the user.
- Use prompt() to take input from the user and display it back.
- Use console.log() to debug and print messages in the console.
Task 4
Manipulate HTML Content
- Use document.getElementById() to change the content of an HTML element.
- Create a button that changes the text of a paragraph when clicked.
- Use functions to dynamically add or remove content from the page.
Task 5
Style HTML Tags with JavaScript
- Change the color, font size, and background of an HTML element using JavaScript.
- Create a button that toggles between two styles for an element.
- Use inline styles to dynamically modify an element's appearance.
Task 6
Work with Events and Functions
- Add an onclick event to a button to execute a function.
- Use mouseover and mouseout events to change the style of an element.
- Display a message in the console when a form is submitted.
Task 7
Create Interactive Webpages
- Use prompt() to ask the user for their name and display a personalized greeting.
- Create a small form and use JavaScript to validate the input fields.
- Add a print button that triggers the browser's print dialog.