Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>03_JavaScript-foundations__loops-conditionals</title>
<script src="/loops-conditionals/conditionals/exercise_00.js" defer></script>
<script src="/loops-conditionals/conditionals/exercise_01.js" defer></script>
<script src="/loops-conditionals/conditionals/exercise_02.js" defer></script>
<script src="/loops-conditionals/loops/exercise_00.js" defer></script>
<script src="/loops-conditionals/loops/exercise_01.js" defer></script>
<script src="/loops-conditionals/loops/exercise_02.js" defer></script>
<script src="/loops-conditionals/while/exercise_00.js" defer></script>
<script src="/loops-conditionals/while/exercise_01.js" defer></script>
<script src="/loops-conditionals/while/exercise_02.js" defer></script>
</head>
<body>
</body>
</html>
31 changes: 31 additions & 0 deletions loops-conditionals/conditionals/exercise_00.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,34 @@
7. At the end of the program, print out: "--- Animal check complete ---"
8. Change the animal to different values to make sure it works in all cases
*/
// exercise1.js

// 1

console.log("--- Animal Checker Program --");

// 2

let animal = "cat";

// 3

if (animal === "cat") {
console.log("Meow");
}

// 5

else if (animal === "dog") {
console.log("Woof");
}

// 6

else {
console.log("Must be an alien");
}

// 7

console.log("--- Animal check complete ---");
12 changes: 12 additions & 0 deletions loops-conditionals/conditionals/exercise_01.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,15 @@

HINT: The modulus operator ( % ) is your friend.
*/

// 1

let number = 8;

// 2

if (number % 2 === 0) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good solution.

Take in account object calisthenics rules in the future 👉 avoid else statement.

https://medium.com/@davidsen/clean-code-object-calisthenics-f6f4dec07c8b

console.log(`Number ${number} is even`);
} else {
console.log(`Number ${number} is odd`);
}
7 changes: 6 additions & 1 deletion loops-conditionals/conditionals/exercise_02.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

Add a comment explaining what is happenning and how to fix it
*/

//The poblem is in the returns, because the first if is completly and return ""You are in elementary school, kid." this text is printed but no is true the solution is or change the order to major if comaprison to minor o delete de equals "
const age = 20;

function checkAge(){
if (age < 3) {
console.log("You're just a baby!");
return;
Expand All @@ -25,3 +26,7 @@ if (age >= 18) {
}

console.log("What? How did this happen!?");
return
}

checkAge()
16 changes: 16 additions & 0 deletions loops-conditionals/loops/exercise_00.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,19 @@

2. Create a for loop that will print out all the odd numbers between 10 and 40.
*/

//1

for (let i = 10; i <= 40; i++) {
if (i % 2 === 0) {
console.log(i);
}
}

//2

for (let i = 10; i <= 40; i++) {
if (i % 2 !== 0) {
console.log(i);
}
}
11 changes: 11 additions & 0 deletions loops-conditionals/loops/exercise_01.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,14 @@
* If it is greater than or equal to 5, print "Logged In with (number)!"
* If it is less than 5, print "Logged Out with (number)!"
*/

for (let i = 1; i <= 10; i++) {

let number = (Math.random() * 10) | 0 + 1;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this expression? 🤔


if (number >= 5) {
console.log(`Logged In with (${number})!`);
} else {
console.log(`Logged Out with (${number})!`);
}
}
16 changes: 16 additions & 0 deletions loops-conditionals/loops/exercise_02.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,19 @@
You made it!
All done!
*/

for (let i = 1; i <= 100; i++) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation is not compliant with requirements.

if (i % 10 === 0) {
console.log(`Checkpoint! ${i}`);
}

if (i === 50) {
console.log("Halfway there!");
}

if (i === 100) {
console.log("You made it!");
}
}

console.log("All done!");
24 changes: 24 additions & 0 deletions loops-conditionals/while/exercise_00.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,27 @@

HINT: Be careful of an infinite loop!
*/
//1

let loggedIn = false;
let attempts = 0;

//2

while (!loggedIn) {
//3

console.log("Incorrect login credentials");

//4

attempts++;
if (attempts === 3) {
loggedIn = true;
}
}

//5

console.log("Successfully logged in!");

20 changes: 20 additions & 0 deletions loops-conditionals/while/exercise_01.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,23 @@

2. Create a while loop that will print out all the odd numbers between 10 and 40.
*/

// 1

let number = 10;
while (number <= 40) {
if (number % 2 === 0) {
console.log(number);
}
number++;
}

// 2

number = 10;
while (number <= 40) {
if (number % 2 !== 0) {
console.log(number);
}
number++;
}
14 changes: 14 additions & 0 deletions loops-conditionals/while/exercise_02.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,17 @@
You made it!
All done!
*/

$counter = 1;

while ($counter <= 100) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation is not compliant with requirements.


if ($counter % 10 == 0) {
echo "Checkpoint! $counter\n";
}

if ($counter == 50) {
echo "Halfwy there!\n";
}