/javascript__loops

tasks - javascript loops

Primary LanguageHTML

Review Assignment Due Date

JavaScript for, while , do-while loops:

Exercises-1πŸ‘¨β€πŸ’»:

Get the sum of two arrays…actually the sum of all their elements. P.S. Each array includes only integer numbers. Output is a number too.

let arr_1 = [3, 5, 22, 5,  7,  2,  45, 75, 89, 21, 2];  // --> 276
let arr_2 = [9, 2, 42, 55, 71, 22, 4,  5,  90, 25, 26]; // --> 351
// Example output: 
// 276 + 351 = 627

Exercises-2πŸ‘¨β€πŸ’»:

Using a for loop print all even numbers up to and including n. Don’t include 0.

let n1 = 22; 
// Example output: 
// 2 4 6 8 10 12 14 16 18 20 22 OR each item on a new line

Exercises-3πŸ‘¨β€πŸ’»:

Using a for loop output the elements in reverse order

let arr = [43, "what", 9, true, "cannot", false, "be", 3, true];
// Example output: 
// true 3.5  be  false cannot  true 9 what 43 OR each item on a new line

Exercises-4πŸ‘¨β€πŸ’»: (Optional)

Given two arrays of integers. Add up each element in the same position and create a new array containing the sum of each pair. Assume both arrays are of the same length.

let arr_3   = [4, 6, 7];
let arr_4    = [8, 1, 9];
// Example output: 
// [12, 7, 16]

Exercises-5πŸ‘¨β€πŸ’»:

Check if a string contains the letter β€œy”. Print β€œyes” if it does and β€œno” if it does not.

let str2 = "don’t know why";
// Example output: 
// β€œyes” 

Exercises-6πŸ‘¨β€πŸ’»:

Given a number n Calculate the factorial of the number

let n2 = 4; //  4 * 3 * 2 * 1 = 24
// Example output:
// 24

Exercises-7πŸ‘¨β€πŸ’»:

Write a program that will check if two strings are palindromes. A palindrome is a word that spells the same forward and backward. Palindrome: a word, phrase, or sequence that reads the same backward as forward, e.g., madam or nurses run.

let str3 = "racecar";
let str4 = "Java";
// Example output:
// string1 palindrome?: 
// Yes 
// string2 palindrome?: 
// No 

Exercises-8πŸ‘¨β€πŸ’»:

Iterate through all numbers from 1 to 45. Print the following:

  • For multiples of 3 print β€œFizz”
  • For multiples of 5 print β€œBuzz”
  • For multiples of 3 and 5 print β€œFizzBuzz”

Exercises-9πŸ‘¨β€πŸ’»:

Print all the elements of the following array(with for loop)

const thisIsAnArray = ["element1", "element2", "element3", "element4"];

Exercises-10πŸ‘¨β€πŸ’»:

Print the EVEN numbers from 10 to -20

input: 10 and -20;
output: 10,8,6,4,2,0,-2,-4,-6,-8..