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
10 changes: 10 additions & 0 deletions .vscode/random/scottie.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>

</body>
</html>
2 changes: 2 additions & 0 deletions 01week/HelloWorld.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
'use strict'
console.log('Hello World')
Empty file added 01week/conditionals.js
Empty file.
11 changes: 11 additions & 0 deletions 01week/rockPaperScissors.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ const rl = readline.createInterface({

// the function that will be called by the unit test below
const rockPaperScissors = (hand1, hand2) => {
let Hand1 = hand1.toLowerCase().trim();
let Hand2 = hand2.toLowerCase().trim();
if(hand1 === hand2) {
return "It's a tie!"
}
else if(Hand1 === "rock" && Hand2 === "scissors" || Hand1 === 'paper' && Hand2 === "rock" || Hand1 === 'scissors' && Hand2 === "paper"){
return "Hand one wins!"
}
else {
return "Hand two wins!"
}

// Write code here
// Use the unit test to see what is expected
Expand Down
28 changes: 26 additions & 2 deletions 02week/pigLatin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,33 @@ const rl = readline.createInterface({

const pigLatin = (word) => {

// Your code here
let str = word;
// Convert string to lowercase
str = str.toString().toLowerCase();
// Initialize array of vowels
const vowels = ["a", "e", "i", "o", "u"];
// Initialize vowel index to 0
let vowelIndex = 0;

if (vowels.includes(str[0])) {
// If first letter is a vowel
return str + "yay";
} else {
// If the first letter isn't a vowel i.e is a consonant
for (let char of str) {
// Loop through until the first vowel is found
if (vowels.includes(char)) {
// Store the index at which the first vowel exists
vowelIndex = str.indexOf(char);
break;
}
}
// Compose final string
return str.slice(vowelIndex) + str.slice(0, vowelIndex) + "ay";
}
}


}


const getPrompt = () => {
Expand Down
14 changes: 14 additions & 0 deletions 02week/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function longestString(sentence) {

let sentenceArr = sentence.trim().split(" ");
let longestCandidate = sentenceArr[0];
for (let i=0; i< sentenceArr.length; i++) {
let currentWord = sentenceArr[i];
if (currentWord.length > longestCandidate.length) {
longestCandidate = currentWord;
}
}
return longestCandidate;

}
console.log(longestString("The lazy dog jumped over the brown cow"));
23 changes: 23 additions & 0 deletions 03week/Towers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
let board = {
towerA: [],
towerB: [],
towerC: []
}


board.towerA.push(7);
board.towerC.push(4);
board.towerC.push(1);

let fromTower = board.towerA;
let toTower = board.towerC;

// get the last value of the object
let lastFrom = fromTower[fromTower.length-1];
let lastTo = toTower[toTower.length-1];

// move pieces
let poped = fromTower.pop();
toTower.push(poped);

console.log(board);
21 changes: 21 additions & 0 deletions 03week/todo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!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>
<h1>The Best ToDo Tracker</h1>
<ul>
</ul>
<input type="text" id="inputText"> <button id='addButton'> add</button>
</input>
</body>
<style>
.done {
text-decoration: line-through;
}
</style>
<script src="todo.js"></script>
</html>
58 changes: 58 additions & 0 deletions 03week/todo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
console.log("Loaded todo.js file");
//when the add button gets clicked
// append the text to the bottom of the list
// add a new list item
let addButton = document.getElementById('addButton');
addButton.addEventListener('click', function(){

let inputElement = document.getElementById('inputText');
let todoText = inputElement.value;
inputElement.value = '';
let li = document.createElement('li');
let span =document.createElement('span');
span.innerText = todoText;
let deleteButton = document.createElement('button');
deleteButton.innerText = 'delete';
deleteButton.classList.add('delete');

let ul =document.querySelector('ul');
ul.appendChild(li);
li.appendChild(span);
li.appendChild(deleteButton);
setupDeleteEvent(deleteButton);
setupSpanEvent(span);
})

// when a delete button get clicked
// delete its parent list item

let allDeletes = document.querySelectorAll('.delete');
for(let i=0; i<allDeletes.length; i++) {
let deleteButton = allDeletes[i];
setupDeleteEvent(deleteButton);
}

function setupDeleteEvent(deleteButton) {
deleteButton.addEventListener('click', function(){
console.log("delete got clicked, parent li is", deleteButton.parentElement);
let parentLi = deleteButton.parentElement;
parentLi.remove();
})
}
// when span is clicked
// class done should be added to it

let allSpans = document.querySelectorAll('span');
//console.log("All spans", allSpans)
for(let i=0; i<allSpans.length; i++) {
let span = allSpans[i];
setupSpanEvent(span);
}


function setupSpanEvent(span) {
span.addEventListener('click', function(event){
console.log("this span got clicked", event)
span.classList.toggle("done");
})
}
46 changes: 34 additions & 12 deletions 03week/towersOfHanoi.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const rl = readline.createInterface({
output: process.stdout
});


let stacks = {
a: [4, 3, 2, 1],
b: [],
Expand All @@ -18,32 +19,52 @@ function printStacks() {
console.log("b: " + stacks.b);
console.log("c: " + stacks.c);
}

function movePiece() {
// Your code here
//act
function movePiece(A, B) {
if (isLegal(A,B)) {
let temp = A[A.length -1];
B.push(temp);
A.pop();
}
checkForWin(stacks.a,stacks.b,stacks.c);

}

function isLegal() {
// Your code here

// source has to be less than the destination
function isLegal(A, B) {
if ((A || B) == null) {
return false;
}
if (B.length == 0){
return true;
}
if (A[A.length -1]< B[B.length -1]) {
return true;
} else {
return false;
}
}

function checkForWin() {
// Your code here
function checkForWin(A, B, C) {
if (A.length == 0 && (B.length == 0 || C.length == 0)) {
console.log('You win!');
process.exit(0);
}

}

function towersOfHanoi(startStack, endStack) {
// Your code here
let fromStack = stacks[startStack];
let toStack = stacks[endStack];
console.log(movePiece(fromStack, toStack));


}

function getPrompt() {
printStacks();
rl.question('start stack: ', (startStack) => {
rl.question('end stack: ', (endStack) => {
towersOfHanoi(startStack, endStack);
towersOfHanoi(startStack.toLowerCase().trim(), endStack.toLowerCase().trim());
getPrompt();
});
});
Expand Down Expand Up @@ -87,7 +108,8 @@ if (typeof describe === 'function') {
});
});

} else {
}
else {

getPrompt();

Expand Down
57 changes: 57 additions & 0 deletions 04week/loop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict'
let Person1 = {
firstName: 'Jane',
lastName: 'Doe',
birthYear: 1925,
gender: 'female'
}
let x = Person1.birthYear
function isOdd(x) {
if (x%2 !== 0){
return x;
}
}
for (Person1[2] in Person1) {
if (isOdd(x) == x) {
console.log(isOdd(x));
}
};
let Person2 = {
firstName: 'Jim',
lastName: 'Boyo',
birthYear: 1928,
gender: 'male'
};
let Person3 = {
firstName: 'Chad',
lastName: 'Volnie',
birthYear: 1991,
gender: 'male'
};

let arrayOfStudents = [Person1, Person2, Person3];
let mapFunction = function(element, index) {
return ` Name is: ${element.firstName} ${element.lastName} Birth date: ${element.birthYear} gender: ${element.gender}`;
};
let map = arrayOfStudents.map(mapFunction);
console.log(map);

let isMaleFilter = function(element, index) {
if (element.gender == 'male') {
return true;
} else {
return false;
}
}
let isMale = arrayOfStudents.filter(isMaleFilter);
console.log('The Males are as follows:', isMale)

let birthYearFilter = function(element, index) {
if (element.birthYear < 1990) {
return true;
} else {
return false;
}
}
let birthYear = arrayOfStudents.filter(birthYearFilter);
console.log('The people born before Jan 1, 1990 is as follows:', birthYear)
10 changes: 7 additions & 3 deletions 04week/mastermind.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ function generateHint() {
}

function mastermind(guess) {
solution = 'abcd'; // Comment this out to generate a random solution
// your code here
let solution = 'abcd'; // Comment this out to generate a random solution
if (guess === solution) {
return 'you guessed it!';
} else {
return 'that is wrong.';
}
}


function getPrompt() {
rl.question('guess: ', (guess) => {
mastermind(guess);
console.log(mastermind(guess))
printBoard();
getPrompt();
});
Expand Down
Loading