0% found this document useful (0 votes)
9 views

JAVASCRIPT TASK 2

The document contains a series of programming tasks primarily focused on JavaScript, including variable declarations, data types, functions, and DOM manipulation. It covers a range of topics from basic variable assignments to more complex operations like creating functions and handling arrays and objects. Each task is designed to enhance understanding of JavaScript fundamentals and practical applications.

Uploaded by

yogasamitha2002
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

JAVASCRIPT TASK 2

The document contains a series of programming tasks primarily focused on JavaScript, including variable declarations, data types, functions, and DOM manipulation. It covers a range of topics from basic variable assignments to more complex operations like creating functions and handling arrays and objects. Each task is designed to enhance understanding of JavaScript fundamentals and practical applications.

Uploaded by

yogasamitha2002
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Task Questions:

===============

1)Declare a variable called name and assign it your name.

2)Change the value of the name variable to your favorite color.

3)Declare a constant variable called pi and assign it the value of π (3.14).

4)Create two variables, a and b, assign them numbers, and calculate their sum.

5)Create two string variables, firstName and lastName, and combine them into a full
name.

6)Create a boolean variable called isActive and set it to true.

7)Create an array called fruits and add three different fruits to it.

8)Create an object called person with properties name, age, and city.

9)Use typeof to determine the type of the fullName variable.

10)Create a variable called age and assign it a numeric value representing your
age.

11) Create a variable called greeting and assign it a string that says "Hello,
World!".

12)Create a variable called isStudent and assign it a boolean value indicating


whether you are a student or not.

13)Create an array called colors and add at least three color names to it.

14)Create an object called car with properties make, model, and year.

15)Create a variable called nickname without assigning any value to it, and log its
value to the console.

16)Create a variable called middleName and explicitly assign it a null value.

17)Create a variable called value and assign it a number. Use typeof to check its
data type.

18)Create a JavaScript object representing a car with properties like make, model,
and year.

19)How do you access the model property of the car object?

20) Update the year property of the car object to 2021.

21)How can you loop through all properties of the car object and log them?

22)Create an object representing a person with a nested object for their address,
which includes street, city, and zipcode.

23)How do you access the city property of the address nested within the person
object?

24)Write a function that checks if a number is positive, negative, or zero. Return


a string that indicates the result.

25) Create a function that takes a day number (1-7) and returns the corresponding
day of the week.

26)Create a function that uses a while loop to print all even numbers from 1 to 50.

27) Write a function that takes two numbers and returns their sum, difference,
product, and quotient.

28)Write a function that checks if a number is greater than, less than, or equal to
another number.

29)Write a function that takes a number and increases it by 5 using the addition
assignment operator.

30)Write a function that returns "Even" or "Odd" based on a given number.

31)Write a function that takes an array of numbers and returns the sum of all the
elements using reduce method.

32)Create a function that returns the maximum value from an array of numbers.

33)Write a function that takes an array and returns a new array that is the reverse
of the original.

34)Write a function that filters out all even numbers from an array.

35)Create a function that flattens a nested array (an array of arrays) into a
single array.

36)Write a function that takes an array of numbers and returns it sorted in


ascending order.

37)Create a function that checks if a given value is present in an array.

38)Create a function that returns a new array containing the squares of each number
from the original array.

39) Create a function that returns the length of a given string.

40)How can you convert the string text = "Python Is Fun" to all lowercase?

41)How can you remove leading and trailing whitespace from the string

42)How would you replace the word "fun" with "awesome" in the string sentence =
"Python is fun!"?

43)How can you split the string fruits = "apple,banana,cherry" into a list of
fruits?

44)How can you find the index of the first occurrence of the letter "o" in the
string my_string = "Hello, World!"?

45)How would you check if the string filename = "report.pdf" starts with "report"?

46)How can you verify if the string url = "https://www.example.com" ends with
".com"?
47) How can you calculate 2 raised to the power of 3.

48)How would you find the square root of 16 in JavaScript?

49)What method would you use to find the absolute value of -10?

50) How would you find the maximum and minimum values in the array let numbers =
[5, 10, 3, 8];?

51)How would you declare a function named greet that takes a parameter name and
logs "Hello, [name]!" to the console?

52)What code would you use to create a function expression named sum that takes two
parameters and returns their sum?

53)How can you define an arrow function named multiply that takes two parameters
and returns their product?

54)How would you write a function called square that takes a number and returns its
square?

55)How would you select an element with the ID myElement and change its text
content to "Hello, World!"?

56)How can you create a new <div> element and append it to the body of the
document?

57)How can you add a click event listener to a button with the ID myButton that
logs "Button clicked!" to the console?

58)Write code to change the font size of an element with the class text to 20px.

59)How can you get all <li> elements from a <ul> with the ID myList and log them to
the console?

60)Write code to change the background color of a <div> with the class hoverDiv to
yellow when the mouse hovers over it.

61)How can you add an input event listener to an <input> field with the ID
searchInput that logs the current value as the user types?

You might also like