Java Script - Assignments - Part 1
Java Script Assignments Part 1
1.
Write a program that declares two
variables, assigns them each a number value, and then adds them together. Print
the result to the console.
2.
Write a program that declares two
variables, assigns them each a string value, and then concatenates them
together. Print the result to the console.
3.
Write a program that declares a variable,
assigns it a Boolean value, and then prints the opposite value to the console.
4.
Write a program that declares a variable,
assigns it an array value containing several strings, and then prints the
length of the array to the console.
5.
Write a program that declares a variable,
assigns it an object value containing several key-value pairs, and then prints
one of the values to the console.
6.
Write a program that declares two
variables, assigns them each a number value, and then compares them using the
greater than operator. Print the result to the console.
7.
Write a program that declares a variable,
assigns it a string value, and then checks if it contains a specific substring
using the includes method. Print the result to the console.
8.
Write a program that declares a variable,
assigns it a number value, and then increments it using the increment operator.
Print the result to the console.
9.
Write a program that declares a variable,
assigns it an array value containing several numbers, and then uses a loop to
print each element of the array to the console.
10.
Write a program that declares a variable,
assigns it an object value containing several key-value pairs, and then uses a
loop to print each key and value to the console.
11.
Write a program that prompts the user for
a number, and then checks if it is even or odd. Print the result to the
console.
12.
Write a program that prompts the user for
a number, and then checks if it is positive or negative. Print the result to
the console.
13.
Write a program that prompts the user for
a string, and then checks if it contains the letter "a". Print the
result to the console.
14.
Write a program that prompts the user for
a number, and then prints all the even numbers up to that number to the
console.
15.
Write a program that prompts the user for
a number, and then prints all the odd numbers up to that number to the console.
16.
Write a program that prompts the user for
a number, and then prints the factorial of that number to the console.
17.
Write a program that prompts the user for
a number, and then checks if it is a prime number. Print the result to the
console.
18.
Write a program that prompts the user for
a number, and then prints the Fibonacci sequence up to that number to the
console.
19.
Write a program that prompts the user for
a string, and then prints each character of the string to the console using a
for loop.
20.
Write a program that prompts the user for
a number, and then prints a multiplication table for that number up to 10 to
the console.
21.
Write a function that takes two numbers
as parameters and returns their sum.
22.
Write a function that takes two strings
as parameters and concatenates them together. Return the result.
23.
Write a function that takes a number as a
parameter and returns true if it is even, and false otherwise.
24.
Write a function that takes a number as a
parameter and returns true if it is a prime number, and false otherwise.
25.
Write a function that takes an array of
numbers as a parameter and returns the largest number in the array.
26.
Write a function that takes an array of
strings as a parameter and returns the longest string in the array.
27.
Write a function that takes a string as a
parameter and returns a new string with all the vowels removed.
28.
Write a function that takes an array of
numbers as a parameter and returns the sum of all the even numbers in the
array.
29.
Write a function that takes a number as a
parameter and returns the factorial of that number.
30.
Write a function that takes a number as a
parameter and returns the Fibonacci sequence up to that number as an array.
31.
Write a program that creates an array
containing several strings, and then prints each string to the console.
32.
Write a program that creates an array
containing several numbers, and then prints the sum of all the numbers to the
console.
33.
Write a program that creates an object
representing a person, with properties for name, age, and gender. Print the
object to the console.
34.
Write a program that creates an array of
objects representing people, with properties for name, age, and gender. Print
the array to the console.
35.
Write a program that creates an array
containing several numbers, and then sorts the array in ascending order. Print
the sorted array to the console.
36.
Write a program that creates an array
containing several strings, and then sorts the array in alphabetical order.
Print the sorted array to the console.
37.
Write a program that creates an object
representing a car, with properties for make, model, and year. Add a method to
the object that prints the make and model to the console.
38.
Write a program that creates an array of
objects representing cars, with properties for make, model, and year. Add a
method to each object that prints the make and model to the console.
39.
Write a program that creates an array of
numbers, and then uses the map method to create a new array with each number
multiplied by 2. Print the new array to the console.
40.
Write a program that creates an array of
objects representing people, with properties for name, age, and gender. Use the
filter method to create a new array containing only the people who are over 30
years old. Print the new array to the console.
41.
Write a program that changes the text of
a paragraph element on the page to "Hello, World!" using JavaScript.
42.
Write a program that changes the
background color of a div element on the page to red when the user clicks a
button.
43.
Write a program that creates a new
paragraph element and adds it to the page when the user clicks a button.
44.
Write a program that changes the font
size of a paragraph element on the page to 24px when the user hovers over it.
45.
Write a program that adds a new class to
a div element on the page when the user clicks a button.
46.
Write a program that creates a new image
element and sets its source to a specified URL when the user clicks a button.
47.
Write a program that changes the text
color of a paragraph element on the page to blue when the user clicks a button.
48.
Write a program that changes the text of
a button element on the page to "Clicked!" when the user clicks it.
49.
Write a program that hides a paragraph
element on the page when the user clicks a button.
50.
Write a program that shows a hidden
paragraph element on the page when the user clicks a button.
51.
Write a program that displays an alert
message when the user clicks a button.
52.
Write a program that changes the
background color of a div element when the user hovers over it.
53.
Write a program that adds a new paragraph
element to the page when the user double-clicks on a button.
54.
Write a program that logs a message to
the console when the user submits a form.
55.
Write a program that prevents the default
action of a link when the user clicks on it.
56.
Write a program that displays a message
when the user right-clicks on an image.
57.
Write a program that changes the font
size of a paragraph element when the user scrolls up or down on the page.
58.
Write a program that changes the
background color of a div element when the user presses a key on the keyboard.
59.
Write a program that displays a message
when the user's mouse enters a specified area on the page.
60.
Write a program that displays a message
when the user's mouse leaves a specified area on the page.
61.
Write a program that throws an error when
a variable is undefined, and use a try-catch block to handle the error.
62.
Write a program that throws an error when
a function is called with an incorrect number of arguments, and use a try-catch
block to handle the error.
63.
Write a program that throws an error when
a user enters an invalid value into a form field, and use a try-catch block to
handle the error.
64.
Write a program that uses console.log to
debug a piece of code that is not working correctly.
65.
Write a program that uses the debugger
statement to debug a piece of code that is not working correctly.
66.
Write a program that throws an error when
a user enters a negative number into a form field, and displays an error
message to the user.
67.
Write a program that uses the
console.trace method to log a trace of the function call stack.
68.
Write a program that catches a TypeError
when trying to access a property of an undefined object, and displays an error
message to the user.
69.
Write a program that catches a
SyntaxError when a user enters an invalid value into a form field, and displays
an error message to the user.
70.
Write a program that uses the
try-catch-finally block to handle errors and perform cleanup tasks, such as
closing a file or releasing a resource.
Comments
Post a Comment