Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
21 views

JavaScript Tasks (2)

The document outlines a series of JavaScript tasks divided into problem sets, focusing on loops, functions, and basic programming concepts. Problem Set 3 includes tasks for printing even and odd numbers, summing numbers, and creating patterns using loops. Problem Set 4 and 5 involve functions for sorting, greeting, checking age, variable swapping, and creating a NodeJS server to display the current date and time.

Uploaded by

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

JavaScript Tasks (2)

The document outlines a series of JavaScript tasks divided into problem sets, focusing on loops, functions, and basic programming concepts. Problem Set 3 includes tasks for printing even and odd numbers, summing numbers, and creating patterns using loops. Problem Set 4 and 5 involve functions for sorting, greeting, checking age, variable swapping, and creating a NodeJS server to display the current date and time.

Uploaded by

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

JavaScript Tasks

Problem Set 3

1. Define a for loop which will print out only the even numbers between 0 and
50.
a. Use the modulus (%) operator in this operation.
b. Do not use the modulus operator in this operation.
Note: that this will leave you with 2 separate answers to this (7)
question.
2. Define a loop which will print out the sum of all the numbers between 0 and
20
3. Define a loop which will print out all the odd numbers between 0 and 100.

Problem Set 4

1. Print out to the console the following patterns using the for loop alongside
the break/continue keywords;
Optional: Use a nested loop to achieve these.
a. #####
#####
#####
#####

b. *****
*****
*****
***

c. #
##
###
####
#####

2. Define a that prints out the sum of 4 numbers that it receives.

3. Define a function that arranges any three numbers it receives in ascending


order.

4. Define a function that will receive a person’s name as a string and then print
out a greeting containing the name that the function received to the console.
Greeting is “Hello John, how are you?”.

5. Define a function which will receive a name and an age, and then within the
function, check if the age which was received is greater than or equal to 18, if
so, print out “Hi John, you are old enough”. If the age is less than 18, print out
“HI John, sorry, but you are not old enough”

Problem Set 5
1. Write a program to check if the value of a variable is an even number or not.
2. Declare a variable flower and assign it the value rose. Declare a second
variable tree and assign it the value apple. Think of a way to swap the values
of flower and apple, such that when you print flower, apple is displayed and
when you print tree, rose is displayed.
3. Write a program to check if the number of characters in a word the user
would input is even or odd. E.g

INPUT: Deebug
OUTPUT: even

INPUT: institute
OUTPUT: odd
4. Write a program to collect 3 different numbers from the user and print the
greatest among the three.

5. Create a NodeJS server application that will display the current date and time
in the following format as a response to a request using your browser as a
client.
Time: 06:03 P.M
Date 14:02:2022
If it is morning, it should show A.M.; if evening, show P.M
Hint: Use a module called "moment”.

If you have any questions, please ask. But digest the assignment properly before
asking.

You might also like