Unit V - Lesson 4

6.4.1. if-else statement

// write your code below this line
if((year % 4 === 0 && year % 100 !==0) || year % 400 === 0){
	var nDays = 366;
}else{
	var nDays = 365;
}

6.4.2. switch-case statement

// write your code below this line

switch (colorCode) {
	case 'V':
		colorName='Violet';
		break;
	case 'I':
		colorName='Indigo';
		break;
	case 'B':
		colorName='Blue';
		break;
	case 'G':
		colorName='Green';
		break;
	case 'Y':
		colorName='Yellow';
		break;
	case 'O':
		colorName='Orange';
		break;
	case 'R':
		colorName='Red'
		break;
}

6.5.1. for loop

function computeSeries(){
	let seriesN = 0;
	for(let i = 1; i<=N; i++){
		seriesN += i ** 2;
	}
	window.seriesN = seriesN;
}
computeSeries();

6.5.2. for loop - continue statement

let sum = 0;
for(let i = 1; i<=N; i++){
	let square = i * i;
	if(square % 10 === 0){
		continue;
	}
	sum+=square;
}
seriesN = sum;

6.5.3. while loop

let a = 1, b = 1;
if (N === 1 || N === 2){
	fibN = 1;
}else{
	let count = 2;
	while(count < N){
		fibN = a + b;
		a = b;
		b = fibN;
		count ++
	}
}
fibN;

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.