For loop and while loop on Js

write a Js program that will display Nos from 1-100 and should display these; In place of numbers divisible by 3 should write “CAT” and numbers divisible by 5 should write “FISH” and in place of numbers divisible by 3 and 5 should write “CATFISH” and display a summary.

What have you tried so far? If you complete the Basic Javascript course here on FCC, you should have enough knowledge to be able to easily write this yourself.

<!DOCTYPE html>
<html>
<head>
	<title>Working With For Loop</title>
</head>
<body>
	<h1>Working With For Loop</h1>
	<script>
		for (var i = 0; i <= 100; i++){
			document.write(i + ', ')

		}
	</script>
	<h1>Sum of Number Divisible by 5 from 1-100</h1>
	<script>
		let sum = 0;
		for (var i = 0; i <= 100; i = i+5){
			sum = sum + i;
		}
		document.write("Sum of Nos Divisible'by 5 from 1-100 is " + sum);
	</script>

</body>
</html>

And i’m new here, please how do i go about this?

If by that you mean how to take the course, you can just follow the link and that’ll get you started on the JS course. If you’re completely new to FCC, then you’ll want to create a profile – just head to www.freecodecamp.org and hit the big yellow button to get started :slight_smile:

As for the code you posted, I believe the challenge is asking you to write a single loop, from 1 to 100, then for each number, print either “CAT”, “FISH”, “CATFISH”, or the number, depending on the rules given in the problem text. (This problem is usually called “FizzBuzz”, after the text the original problem wanted you to print).

I’m not entirely sure what “display a summary” means in this context though, but if you keep a running total similar to what you’re doing in the second loop, that would probably suffice. Don’t worry too much about the summary to start – just worry about printing the CAT/FISH/CATFISH parts for now.

To test whether a number is evenly divisible by another number, you want the modulus or “mod” operator (sometimes called “remainder”), which is % in javascript. For example, this code below tests whether a number is divisible by 7:

let x = 123;
if (x % 7 === 0) {
    console.log("x is divisible by 7");
} else {
    console.log("x is not divisible by 7");
}