Skip to content

Commit

Permalink
1/5
Browse files Browse the repository at this point in the history
  • Loading branch information
5nue committed Jan 5, 2024
1 parent 6a3fff0 commit 6307de4
Show file tree
Hide file tree
Showing 16 changed files with 653 additions and 13 deletions.
22 changes: 22 additions & 0 deletions 12072023.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
let x = 5

let arr = [[1,2,3],
['Chinue', 'Chang'],
[true, false]]

for(y of arr){
for(z of y){
console.log(z)
z++
}
}

// for (let i = 0; i<arr.length; i++) { // for each array in the main array
// for (j = 0; j < arr[i].length; j++){ // for each element in the array in the main array
// if (typeof arr[i][j] == "string" && j == 0){ // if that element is a string And is at the first position
// for (char of arr[i][j]) // log each character in that element to the console
// console.log(char);
// }
// }
// }

13 changes: 13 additions & 0 deletions 120720231.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let arr = [0, 4, 5, 6, 3, 2, 1]

for (let i = 0; i < arr.length; i++){ //iterating through the array
for (let j = 0; j < arr.length; j++){ // iterating through the array each time i increases by one (iterates 100 times)
if (arr[j] > arr[j + 1]){ // if the element at position j is more than the element directly ahead of it
let temp = arr[j]; // temp equals arr[j]
arr[j] = arr [j+1]; // arr[j] now equals the next element of
arr[j+1] = temp; // and the next element ahead equals (which was the first arr[j] before it was changed)
}
}
}

console.log(arr)
77 changes: 77 additions & 0 deletions Homework.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Make a function that takes in an array and a target number that returns two numbers from the array that equal the target

// else, return "No number equals the target"

// function twoSum(a, b) {
// for (let i = 0; i < a.length; i++){
// for (let j = i + 1; j < a.length; j++){
// if (a[j] + a[i] === b){
// return [a[j],a[i]]
// }
// }
// }
// return "No number equals the target"
// }
// console.log(twoSum([1,2,10, 89, 32],99));

let board = [
[0, 1 ,0],
[0, 1 ,0],
[1, 0 ,1]
];
// function ticTacToe (a, b, c) {
// if (a ! = 0 && a == c && a == b && b == c)
// }
function ticTacToe(a, b, c){
if(a == b && a == c && b == c) {
return true;
} else{
return false;
}
}

// console.log (ticTacToe(board[1][0], board[1][1]))

function checkWinner (board) {

// RIGHT
for (let row = 0; row < 3; row++){
for (let column = 0; column < 3; column++){
if (ticTacToe(board[row][column], board[row][column + 1], board[row][column + 2])) {
return "Three in a row!"
}
}
}

// UP AND DOWN

for (let row = 0; row < 1; row++){
for (let column = 0; column < 3; column++){
if (ticTacToe(board[row][column], board[row][column + 1], board[row][column + 2])) {
return "Three in a row!"
}
}

}

// DIAGONAL RIGHT
for (let row = 0; row < 1; row++){
for (let column = 0; column < 3; column++){
if (ticTacToe(board[row][column], board[row+1][column + 1], board[row+2][column + 2])) {
return "Three in a row!"
}
}

}

// DIAGONAL LEFT
for (let row = 0; row < 1; row++){
for (let column = 0; column < 3; column++){
if (ticTacToe(board[row][column], board[row+1][column - 1], board[row+2][column - 2])) {
return "Three in a row!"
}
}

}
}
console.log(checkWinner(board))
49 changes: 49 additions & 0 deletions Homework1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
let battleShipOne = [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
]

let battleShipTwo = [
[1, 0, 0],
[0, 1, 0],
[0, 0, 1]
]

function battleShips (a, b, c){
if(a == b && a == c && b == c) {
return Win;
} else{
return Lose;
}
}

console.log (battleShips[0][0], board[0][0])

// function battleShips() {
// const userChoice = prompt('Choose a row:');
// const validChoices = [''] ;
// if (!validChoices.includes(userChoice)) {
// alert('Wrong.');
// return;
// }
// const userChoiceTwo = prompt('Choose a column:');
// const validChoicesTwo = [''] ;
// if (!validChoicesTwo.includes(userChoiceTwo)) {
// alert('Wrong.');
// return;
// console.log(`You chose: ${userChoice}`);
// console.log(`You chose: ${userChoiceTwo}`);
// }

// const result = battleShips();
// alert(result);









Loading

0 comments on commit 6307de4

Please sign in to comment.