Skip to main content

Task 24: Difference between FOR and WHILE and DO-WHILE

Start with Affirmation​

  • "I am destined for greatness. Every step I take brings me closer to my goals. I embrace challenges, knowing they are stepping stones to success. My mind is focused, my heart is determined, and my actions are aligned with my dreams."

Daily Affirmations for Success

  • βœ… I am capable, confident, and unstoppable.
  • βœ… Success flows to me because I take consistent action.
  • βœ… I attract opportunities that align with my purpose.
  • βœ… My hard work and persistence create abundance.
  • βœ… I am always learning, growing, and evolving.
  • βœ… I believe in my potential and trust my journey.
  • βœ… I turn setbacks into comebacks with resilience.
  • βœ… I am grateful for every success, big and small.

Success Reflection​

"Every effort I made today has planted seeds for my future success. I release any doubts and trust the process. My dreams are possible, and I am getting closer every day. I am grateful, I am strong, and I am ready for more!"

πŸ’ͺ Repeat daily, feel the power, and watch your success unfold!


πŸ”Ή If you don’t understand the task, watch the video above for the answer.


Task​

Step 1​

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Countdown Timer</title>
</head>
<body>
<h1>⏳ Countdown from 10 to 1</h1>
<button onclick="startCountdown()">Start Countdown</button>
<div id="output"></div>

<script src="script.js"></script>
</body>
</html>

Step 2​

const outputDiv = document.getElementById("output");

function startCountdown() {
outputDiv.innerHTML = "<h2>πŸš€ Countdown Using For Loop</h2>";

// FOR LOOP
for (let i = 10; i >= 1; i--) {
outputDiv.innerHTML += `🟑 ${i}<br>`;
}

outputDiv.innerHTML += "<h2>πŸ” Countdown Using While Loop</h2>";

// WHILE LOOP
let j = 10;
while (j >= 1) {
outputDiv.innerHTML += `πŸ”΅ ${j}<br>`;
j--;
}

outputDiv.innerHTML += "<h2>πŸ”‚ Countdown Using Do-While Loop</h2>";

// DO-WHILE LOOP
let k = 10;
do {
outputDiv.innerHTML += `🟣 ${k}<br>`;
k--;
} while (k >= 1);
}