JSFiddle - React, Tailwind, and code Playground

by dipaks2011

JavaScript

function isLandscape(width, height){
    return (width > height) 
}
//console.log(isLandscape(600, 300)); 

// Sum of multiples of 3 and 5. 
// multiples of 3 from 0 to 10 are: 3, 6, 9 
// multiples of 5 from 0 to 10 are: 5, 10 
//3 + 6 + 9 + 5 + 10 = 33 
function sum(limit){
	let sum = 0; 
	for(let i = 0; i <= limit; i++){
		if(i % 3 === 0 || i % 5 === 0){
			sum += i; // short for: sum = sum + i; 
		}
	}
	return sum;
}
//console.log(sum(10));   

// for...of
const str = new String('Chidume');
//console.log(typeof str[Symbol.iterator]); 

// Calculate grades 
/*
How you will get the job done will define the JS logic you will use to solve
that issue. Here the average is taken out by sum divided by the length or array 
hence you need 'arr' as an argument 
then you need sum to divide the lenght
the length has to be added into sum 
*/
function calculateAverage(arr){
	let sum = 0;
	for (let val of arr) {
		sum += val;
	}
	return sum / arr.length;
}
let marks = [80, 80, 50, 90, 90, 90]; // marks in each subject
//console.log(calculateAverage(marks));
function calculateGrade(marks){
	const average = calculateAverage(marks); 
	if(average < 60) return 'F';
	if(average < 70) return 'E';
	if(average < 80) return 'C';
	if(average < 90) return 'B';
	return 'A';
}
//console.log(calculateGrade(marks));

// 
// Show stars 
function showStars(rows){
	for(let row = 1; row <= rows; row++){
		let pattern = '';
		for(let i = 0; i < row; i++){
			pattern += '*';
		}
		console.log(pattern);
	}
}
//showStars(10); 

/* 
In Math the numbers can be Prime (whose factors are only 1 and itself. It cannot be divided evenly 
with another number) or Composite. 
The factors of 12 are: 1, 2, 3, 4, 6, 12 which means when we divide 12 by these numbers, 
there won't be any reminder - the reminder will be zero. So we can say 12 can be divided evenly by 
its factors, reason why it's a Composite number because it has many factors. 
Prime number in contrast has only 2 factors; 1 and itself. For example,...