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
27 changes: 26 additions & 1 deletion 01week/rockPaperScissors.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,35 @@ const rl = readline.createInterface({

// the function that will be called by the unit test below
const rockPaperScissors = (hand1, hand2) => {

hand1 = hand1.toLowerCase()
hand2 = hand2.toLowerCase()
hand1 = hand1.trim()
hand2 = hand2.trim()
console.log("Checking the hand", hand1)
// Write code here
// Use the unit test to see what is expected

if (hand1 === "rock" && hand2 === "paper"){
return "Hand two wins!";
}
else if (hand1 === "paper" && hand2 === "scissors"){
return "Hand two wins!";
}
else if (hand1 === "scissors" && hand2 === "rock"){
return "Hand two wins!";
}
else if (hand1 === "paper" && hand2 === "rock"){
return "Hand one wins!";
}
else if (hand1 === "rock" && hand2 === "scissors"){
return "Hand one wins!";
}
else if (hand1 === "scissors" && hand2 === "paper"){
return "Hand one wins!";
}
else (hand1 === hand2);{
return "It's a tie!";
}
}

// the first function called in the program to get an input from the user
Expand Down
11 changes: 9 additions & 2 deletions 02week/pigLatin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ const rl = readline.createInterface({


const pigLatin = (word) => {

word = word.toLowerCase();
word = word.trim();
const vowels = word.match(/[aeiou]/);
const firstPosition = word.indexOf(vowels);
// Your code here

if (firstPosition > 0) {
return word.slice(firstPosition) + word.slice(0, firstPosition) + "ay";
}
return word + "yay";
}



const getPrompt = () => {
rl.question('word ', (answer) => {
console.log( pigLatin(answer) );
Expand Down
22 changes: 22 additions & 0 deletions 03week/todo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!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>
<div id="ulWrapper">
<ul>
</ul>
</div>
<input type="text" id="inputText"> <button id="addButton"> add </button>
<script src="todo.js"></script>
</body>
<style>
.done{
text-decoration: line-through;
}
</style>
</html>
66 changes: 66 additions & 0 deletions 03week/todo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
'use strict';

let addButton = document.getElementById("addButton");
addButton.addEventListener('click' , function(){
console.log("clicked the add button");

let inputElement = document.getElementById('inputText');
let todoText = inputElement.value;
inputElement.value = '';

//create an li element
let li = document.createElement("li");

//create a span element
let span = document.createElement("span");
//update the inner text of the span element
span.innerText = todoText;

//create a delete button
let deleteButton = document.createElement("button");
//update the inner text of the delete button
deleteButton.innerText = 'delete';
//add a class to the delete button
deleteButton.classList.add("delete");

//add the li to the bottom of the ul element
let ul = document.querySelector("ul");
ul.appendChild(li)

//add the span and the delete button as children of the newly created li
li.appendChild(span);
setupSpanEvent(span);
li.appendChild(deleteButton);
setupDeleteEvent(deleteButton);
})

//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();
});
}



let allSpans = document.querySelectorAll("span");
for (let i = 0; i < allSpans.length; i++) {
let span = allSpans[i];
setupSpanEvent(span);
}
function setupSpanEvent(span){
span.addEventListener("click", function(){
console.log("This span got clicked", span);
span.classList.toggle("done");
})
}