T

@Tammar_Haider

4) Program to join all elements of the following array into a string. myColor = ["Red", "Green"]

NodeJS
3 years ago
console.log(Join(["Red","Green"])); console.log(Join(["Red","Green","Black","White"])); console.log(["Red","Green"]) function Join(Arr) { var NewArr = Arr.join(); return NewArr }

Write a JavaScript function to get the last element of an array. exp ([7, 9, 0, -2])) O/P : -2

NodeJS
3 years ago
console.log(Last([7,9,0,-2])); console.log(Last('d',3)); console.log(Last([1,3,4])); console.log(Last([7, 9, 0, -2])); console.log(Last([3,7, 9, 0, -1])); console.log(Last([7, 9, 0, -4])); function Last(Arr) { var last = Arr.slice(-1);

Write a JavaScript function to get the first element of an array. Exp ([7, 9, 0, -2] O/P - 7

NodeJS
3 years ago
console.log(first([7,9,0,-2])); console.log(first('d',3)); console.log(first([7, 9, 0, -2],3)); console.log(first([3,7, 9, 0, -2],6)); console.log(first([7, 9, 0, -2],-3)); function first(Arr) { for(var i =0 ; i<1; i++) {

Write a JavaScript function to clone an array. ([1, 2, 4, 0])); ([1, 2, 4, 0])

NodeJS
3 years ago
var ar = new Array(1,2,3,4); console.log('Real Array : '+ ar); // Method 1 var NewAr= ar.slice('') console.log(NewAr); // Mathod 2 var n = Array.from(ar); console.log('Clone array :'+n);

1) Write a JavaScript function to check whether an `input` is an array or not

NodeJS
3 years ago
console.log(is_array('w3resource')); console.log(is_array([1,2,3,4])); function is_array(x) { return Array.isArray(x); }

Write a JavaScript function that checks whether a passed string is palindrome or not?

NodeJS
3 years ago
var p = Palindrome('MadaM'); console.log(p); function Palindrome(x) { var oldArr = x; console.log(oldArr); var Rev = Reverse(oldArr); console.log(Rev); function Reverse(str) {

Write a JavaScript function that reverse a number. Example x = 32243; Expected O/P : 34223

NodeJS
3 years ago
var Rev=0; var Last = " "; var res = Reverse(32243); console.log("Reverse of Number is :"+ res); function Reverse(X) { while(X>0) { Rev = X % 10; Last = Last + Rev;

Factorial program for 4

NodeJS
3 years ago
var res = Fact(4); function Fact(N) { if(N == 0 || N == 1) { return 1; } else { return N * Fact(N-1);

find the armstrong numbers of 3 digits

NodeJS
3 years ago
var num =153; Last = 0; sum=0; while(num>0) { var n = num%10; last= Last+n; sum= sum+(last*last*last); num = Math.floor(num/10);

Write a JavaScript program to compute the greatest common divisor (GCD)of two positive integers.

NodeJS
3 years ago
var a =128; var b = 96; if(a>b) { var rem = a%b; console.log(rem); } else { var rem =b%a;

Write a JavaScript program to sum the multiples of 3 and 5 under 1000.

NodeJS
3 years ago
var sum =0; for(var i =1; i<=1000;i++) { if(i%3==0 && i%5==0) { sum=sum+i; console.log(i); } } console.log(sum);

JavaScript program to construct the following pattern, using a nested for loop.

NodeJS
3 years ago
for(var i = 0 ; i<5 ; i++ ) { for(var j=0 ; j<=i;j++) { console.log("*"); } console.log("\n") }

iterates the integers from 1 to 100. Multiple of free print "Fizz" and Five print "Buzz"

NodeJS
3 years ago
for(var i = 1; i<=150 ; i++) { if(i%3==0) { console.log("Fizz "+i); } if(i%3==0 && i%5==0) { console.log("FzzBuzz "+i); }

compute, the average marks and determine the corresponding grade.

NodeJS
3 years ago
var David = 80 ; Vinoth =77; Divya =88 ; Ishitha =95; Thomas =50; if(David < 60 || David < 70 || David < 80 || David < 90 || David<100) { console.log("D Grade"); } if(Vinoth < 60 || Vinoth < 70 || Vinoth < 80 || Vinoth < 90 || Vinoth<100) { console.log("C Grade"); } if(Divya < 60 || Divya < 70 || Divya < 80 || Divya < 90 || Divya<100)

check if the current number is odd or even Sample Output : "0 is even" "1 is odd" "2 is even

NodeJS
3 years ago
for(var i=0 ; i<=15 ; i++) { if(i%2==0) { console.log(i+" is Even") } else if(i%2 == 1) { console.log(i+" is Odd"); }

Write a JavaScript conditional statement to find the largest of five numbers.

NodeJS
3 years ago
var a= -5;var b=-2;var c=-6; var d=0; var e=-1; if(a>b && a>c && a>d && a>e) { console.log(a); } else if(b>a && b>c && b>d && b>e) { console.log(b); } else if(c>a && c>b && c>d && c>e)

Sort three numbers - Sample numbers : 0, -1, 4 Output : 4, 0, -1

NodeJS
3 years ago
// Method 1 ar arr = new Array(0,-1,4); console.log(arr); var newArr = arr.sort(); console.log(newArr); var ReverseSort = newArr.reverse(); console.log(ReverseSort); // Method 2 var x = 0 ;

find the sign of product of three numbers. Sample numbers : 3, -7, 2 Output : The sign is -

NodeJS
3 years ago
var a =3; var b =-7; var c=2; if(a>0 && b>0 && c>0) { console.log("This sign is +"); } else if(a<0 && b<0 && c<0) { console.log("This sign is -");

. Write a JavaScript program that accept two integers and display the larger.

NodeJS
3 years ago
var input1 = 56 var input2 = 89 if(input1>input2) { console.log(input1+" is larger than "+input2); } else { console.log(input2+" is larger than "+input1);