0% found this document useful (0 votes)
57 views3 pages

JavaScript (Exercice Loop)

The document contains code snippets for three JavaScript exercises: 1) A function to print all elements of a 2D array using nested for loops, 2) A function to delete all occurrences of an element from an array, and 3) A function to calculate the power of a number using a for loop and example calls to print a pattern of increasing numbers.

Uploaded by

Benzaidan Rida
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)
57 views3 pages

JavaScript (Exercice Loop)

The document contains code snippets for three JavaScript exercises: 1) A function to print all elements of a 2D array using nested for loops, 2) A function to delete all occurrences of an element from an array, and 3) A function to calculate the power of a number using a for loop and example calls to print a pattern of increasing numbers.

Uploaded by

Benzaidan Rida
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

Exercice 1

Write a JS code to print a 2D array

Function `printArray()` prints all the elements of a 2D array using nested for
loops.

function printArray(arr) {

// Your code Here

var arr = [[1, 2],

[3, 4],

[5, 6]];

printArray(arr) //1 2 3 4 5 6

Exercice 2

Write a JS code to delete all occurrence of element in given


array

Function `deleteElement()` deletes all the occurrence of element from the


given array.

function deleteElement(arr, ele) {

var arr = [23,56,4,78,5,63,45,210,56];

arr = deleteElement(arr, 56)


console.log(arr); //[23, 4, 78, 5, 63, 45, 210]

Exercice 3
Write a JS code to find the power of a number using for loop

Function numPower() to returns power of number for provided exponential


value using for loop.

function numPower(num,pow) {

//Your code here

console.log(numPower(4,3)); //64

console.log(numPower(16,2)); //256

function printPattern(range) {

printPatter(8);

/* 1

1 2

1 2 3

1 2 3 4
1 2 3 4 5

1 2 3 4 5 6

1 2 3 4 5 6 7

1 2 3 4 5 6 7 8 */

You might also like