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

Javascript Questions.docx

The document contains various JavaScript programming exercises focusing on loops, array methods, and array iteration methods. It includes tasks such as printing squares of numbers, counting vowels, implementing a calculator, manipulating arrays with methods like push, pop, unshift, and shift, and using forEach, map, and filter functions. The exercises aim to enhance understanding of JavaScript syntax and array manipulations.

Uploaded by

shaseliyapri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Javascript Questions.docx

The document contains various JavaScript programming exercises focusing on loops, array methods, and array iteration methods. It includes tasks such as printing squares of numbers, counting vowels, implementing a calculator, manipulating arrays with methods like push, pop, unshift, and shift, and using forEach, map, and filter functions. The exercises aim to enhance understanding of JavaScript syntax and array manipulations.

Uploaded by

shaseliyapri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

JAVASCRIPT QUESTIONS

FOR LOOP:

1.Print the squares of numbers from 1 to 10 using a


f o r loop.
2. Write a program to count the number of vowels (a ,
e, i, o, u) in a string using a for loop.
WHILE LOOP:

1.Implement a simple calculator that performs


addition, subtraction, multiplication, and division
using a while loop until the user chooses to exit.
2.Write a program to reverse an array using a w h i l e
loop.
ARRAY METHODS:
 Create an array studentNames with the names of
4 students.
 A new student joins the class. Add their name
using push().
 The last student leaves. Remove them using
pop().
 A new student is assigned as the class leader and
added to the front using unshift().
 The previous class leader is removed using
shift().
Display the final list of student names.

Create an empty array named planner.


Add "Exercise", "Work" and "Study" using
push().
 You decide not to exercise. Remove the last task
using pop().
 Add "Breakfast" at the beginning using
 unshift().
 Remove the first task using shift().
 Display the remaining tasks.
Convert ["JavaScript", "is", "fun"] to
"JavaScript-is-fun" using join().

 Convert ["Lion", "Tiger", "Elephant"] to


 "Lion,Tiger,Elephant" using toString().
 Convert "HTML,CSS,JavaScript" into an array
 using split().
 Remove "Banana" from ["Apple", "Banana",
 "Mango"] using splice().
Extract the first three elements from [100, 200,
300, 400, 500] using slice().
Merge [10, 20] and [30, 40] using concat().
How can you create a comma-separated string
from an array ["Java", "Python", "C++"] using
join()
 Can you use toString() on a mixed array like
 [1, "Apple", true]? What will be the result?
 If you apply toString() on an empty array [],
what will it return?
You are given a sentence "JavaScript is a
powerful language". Split this into an array of
words.
 If you use split() with an empty string as a
separator (""), what will the output be for
"HELLO"?
 You have an array ["Red", "Green", "Blue",
 "Yellow"]. Remove "Green" using splice().
 Add "Purple" and "Orange" at index 2 using
splice().
How can you replace "Blue" with "Black" using
splice()?
 Remove the last two elements from the array
["Dog", "Cat", "Rabbit", "Horse"] using
splice().
Extract the first 3 elements from the array [100,
200, 300, 400, 500] using slice().
Create a copy of the array ["A", "B", "C", "D"]
using slice().
Extract the last two elements using a negative
index from slice() on [5, 10, 15, 20, 25].
ARRAY ITERATION METHODS:

For each():

1.Convert all the strings in the array to uppercase


using forEach().
2.Add "Hello " as a prefix to each name in the
array using forEach(). var names = ["John", "Emma",
"Liam"];

Map():

3.You are given an array of objects containing users'


first and last names. Create a new array
containing only the first names using m a p (.)
4.Generate a personalized greeting like " H e l l o ,
John!" for each name using map().
FILTER():

5.Given an array of names, filter out only the names


that start with 'A'.
6.
Create a new array that contains only words with
more than 5 letters.

You might also like