-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
653 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
// } | ||
// } | ||
// } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Oops, something went wrong.