Skip to content

Commit

Permalink
Arrays and Loops (Part 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
mj-stack committed Jan 23, 2025
1 parent 4a80e8d commit c8cac99
Show file tree
Hide file tree
Showing 4 changed files with 403 additions and 0 deletions.
246 changes: 246 additions & 0 deletions Lesson-11 Arrays and Loops (Part 2)/lesson11.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>


<script>
// const nums = [10, 20, 30];
// console.log(nums);

// nums[2] = 99;
// console.log(nums);

// function getLastValue(array) {
// console.log(array[array.length - 1])
// }

// getLastValue([1, 20, 22, 24, 5]);
// getLastValue(['hi', 'hello', 'good']);

// function arraySwap(array) {
// let firstValue = array[0];
// let lastValue = array[array.length - 1];

// array[0] = lastValue;
// array[array.length-1] = firstValue;

// console.log(array);
// }

// arraySwap([1, 20, 22, 24, 5]);
// arraySwap(['hi', 'hello', 'good']);

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

// for (let i = 5; i >= 0; i--) {
// console.log(i);
// }

// let i = 0;

// while (i <= 10) {
// console.log(i);
// i+=2;
// }

// let i = 5;

// while (i >= 0) {
// console.log(i);
// i--;
// }


// const newArray = [];

// function addOne(array) {
// for (let i = 0; i < array.length; i++) {
// const num = array[i];

// newArray.push(num + 1);
// }

// console.log(newArray);
// }


// addOne([1, 2, 3]);
// addOne([-2, -1, 0, 99]);

// const newArray = [];

// function addNum(array, add) {

// for (i = 0; i < array.length; i++) {
// const num = array[i];

// newArray.push(num + add);
// }
// console.log(newArray);
// }

// // addNum([1, 2, 3], 2);
// // addNum([1, 2, 3], 3);
// addNum([-2, -1, 0, 99], 2);

// const newArray = [];

// function addArrays(array1, array2) {
// for (let i = 0; i < array1.length; i++) {
// let num1 = array1[i];
// let num2 = array2[i];

// newArray.push(num1 + num2);
// }

// console.log(newArray);
// }

// addArrays([1, 1, 2], [1, 1, 3]);

// const onlyPositive = [];

// function countPositive(nums) {
// let result = 0;

// for (let i = 0; i < nums.length; i++) {
// const num = nums[i];
// if (num > 0) {
// result++;
// }
// }

// return result;
// }

// console.log(countPositive([1,-3, 5]));


// function minMax(nums) {
// const myObject = {
// min: nums[0],
// max: nums[0]
// }

// for (i = 0; i < nums.length; i++) {
// if (nums[i] < myObject.min) {
// myObject.min = nums[i];
// } else if (nums[i] > myObject.max) {
// myObject.max = nums[i];
// }
// }

// return myObject;
// }

// console.log(minMax([1, -3, 5]));
// console.log(minMax([-2, 3, -5, 7, 10]));
// const fruitCount = {}

// function countWords(words) {

// for (i = 0; i < words.length; i++) {
// let fruit = words[i];

// if (!fruitCount[fruit]) {
// fruitCount[fruit] = 1;
// } else {
// fruitCount[fruit]++;
// }
// }

// return fruitCount;
// }

// // console.log(countWords(['apple', 'grape', 'apple', 'apple']));
// console.log(countWords(['apple', 'grape', 'apple', 'apple', 'grape']));


// const myArray = ['hello', 'world', 'search', 'good'];

// for (let i = 0; i < myArray.length; i++) {
// const word = myArray[i];

// if (word === 'search') {
// console.log(i);
// }

// }

// const myArray = ['hello', 'world', 'search', 'good', 'search'];

// for (let i = 0; i < myArray.length; i++) {
// const word = myArray[i];

// if (word === 'search') {
// console.log(i);
// break;
// }
// }

// function findIndex(array, word) {
// for (let i = 0; i < array.length; i++) {

// if (array[i] === word) {
// return i;
// }
// }
// }

// console.log(findIndex(['green', 'red', 'blue', 'red'], 'red'));

// const newArray = [];
// function removeEgg(foods) {
// for (let i = 0; i < foods.length; i++) {
// if (foods[i] === 'egg') {
// continue;
// }
// newArray.push(foods[i]);
// }
// return newArray;
// }

// console.log(removeEgg(['egg', 'apple', 'egg', 'egg', 'ham']));

// const newArray = [];
// function removeEgg(foods) {
// let eggsRemoved = 0;

// const reversedFoods = foods.reverse();

// for (let i = 0; i < foods.length; i++) {
// if (reversedFoods[i] === 'egg' && eggsRemoved < 2) {
// eggsRemoved++;
// continue;
// }
// newArray.push(reversedFoods[i]);
// }
// return newArray.reverse();
// }

// console.log(removeEgg(['egg', 'apple', 'egg', 'egg', 'ham']));

for (let i = 1; i <= 20; i++) {
if (i % 3 === 0 && i % 5 === 0) {
console.log('FizzBuzz');

} else if (i % 3 === 0) {
console.log('Fizz');

} else if (i % 5 === 0) {
console.log('Buzz');

} else {
console.log(i);
}
}
</script>
</body>
</html>
49 changes: 49 additions & 0 deletions Lesson-11 Arrays and Loops (Part 2)/todo-list-project.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
body {
font-family: Arial;
}

.todo1 {
margin-bottom: 34px;
}

.todo2 {
margin-bottom: 34px;
}

.todo-title-grid,
.todo-task-grid {
display: grid;
grid-template-columns: 200px 150px 100px;
column-gap: 10px;
row-gap: 10px;
align-items: center;
}

.todo-title-grid {
margin-bottom: 10px;
align-items: stretch;
}

.todo-name-input,
.todo-duedate-input {
font-size: 15px;
padding: 7px;
padding-left: 6px;
}

.add-todo-button {
background-color: green;
color: white;
border: none;
font-size: 15px;
cursor: pointer;
}

.delete-todo-button {
background-color: darkred;
color: white;
border: none;
padding: 10px;
cursor: pointer;
font-size: 15px;
}
34 changes: 34 additions & 0 deletions Lesson-11 Arrays and Loops (Part 2)/todo-list-project.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Todo-List Project</title>
<link rel="stylesheet" href="todo-list-project.css">
</head>
<body>

<p>Todo List Practice 1</p>
<input type="text" placeholder="Todo name" class="task-input">
<button onclick="addTasks1()" class="todo1">Add</button>

<p>Todo List Practice 2</p>
<input type="text" placeholder="Todo name" class="task-input2">
<button onclick="addTasks2()" class="todo2">Add</button>
<div class="display-todo-task"></div>

<p>Todo List</p>

<div class="todo-title-grid">
<input type="text" placeholder="Todo name" class="js-todo-name-input todo-name-input">
<input type="date" class="js-todo-duedate-input todo-duedate-input">
<button onclick="addTasks3()" class="add-todo-button">Add</button>
</div>

<div class="js-todo-task-grid todo-task-grid">

</div>

<script src="todo-list-project.js"></script>
</body>
</html>
Loading

0 comments on commit c8cac99

Please sign in to comment.