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
61 changes: 61 additions & 0 deletions 03week/PigLatin.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
body {
background: sandybrown;
}

div.title {
display: flex;
justify-content: center;
grid-area: title;
background: red;
width: auto;
height: auto;
margin: 10px;
}

input.input {
padding: 10px;
font-size: 25px;
}

p {
font-size: 25px;
}

h1 {
font-family: Arial, Helvetica, sans-serif;
}

div.input {
display: flex;
justify-content: center;
grid-area: input;
}

div.button {
display: flex;
justify-content: center;
grid-area: button;
}
div.output {
display: flex;
justify-content: center;
grid-area: output;
}

#pigLatinText {
color: red;
font-family: "Times New Roman", Times, serif;
padding: 10px;
font-size: 50px;
}

main {
display: grid;
grid-row-gap: 35px;
grid-template-columns: 1 fr;
grid-template-areas:
"title"
"input"
"button"
"output";
}
25 changes: 25 additions & 0 deletions 03week/PigLatin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<script src="PigLatin.js"></script>
<link rel="stylesheet" href="PigLatin.css" />
</head>
<body>
<main>
<div class="title"><h1>Pig Latin Translator</h1></div>
<div class="input"><p>Enter english word: </p> <input class="input" id="plainText" /></div>
<div class="button">
<button onclick="handleTranslate()">Translate</button>
<br />
</div>
<div class="output">
<span id="pigLatinText"></span>
</div>
</div>
</main>
</body>
</html>
119 changes: 119 additions & 0 deletions 03week/PigLatin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
"use strict";

// const assert = require("assert");
// const readline = require("readline");
// const rl = readline.createInterface({
// input: process.stdin,
// output: process.stdout
// });

//RULES OF PIG LATIN:
//if starts with a vowel add "yay" to end
//if word does not have a vowel add "ay" to the end
//if word has vowel, split word before first vowel, switch halves, and add "ay" to the end

function pigLatin(word) {
word = word.trim().toLowerCase(); //sets word to lowercase
let vowels = ["a", "e", "i", "o", "u"]; //array is created to compare with characters of word
let i; //variables are declared to run tests
let hasvowel = false;
let substring;

if (
//tests to see if first character of word is vowel
word[0] == vowels[0] ||
word[0] == vowels[1] ||
word[0] == vowels[2] ||
word[0] == vowels[3] ||
word[0] == vowels[4]
) {
word = word.concat("yay");
hasvowel = true;
} else {
//runs if first character is not a vowerl
for (i = 0; i < word.length && hasvowel == false; i++) {
if (
//tests to see if any character in string is a vowel
word[i] == vowels[0] ||
word[i] == vowels[1] ||
word[i] == vowels[2] ||
word[i] == vowels[3] ||
word[i] == vowels[4]
) {
//if test returns true substring gets valued assigned and is concated to word. Word is then sliced as needed and concated with 'ay'
substring = word.substring(0, i);
word = word.concat(substring);
word = word.slice(i, word.length);
word = word.concat("ay");
hasvowel = true;
}
}
for (i = 0; i < word.length && hasvowel == false; i++) {
if (
//tests to see if no characters are vowels, which should run if the first two test return false. Will concate 'ay' if test returns true
word[i] !== vowels[0] &&
word[i] !== vowels[1] &&
word[i] !== vowels[2] &&
word[i] !== vowels[3] &&
word[i] !== vowels[4]
) {
word = word.concat("ay");
hasvowel = true;
}
}
}
//modified word gets returned
return word;

// Your code here
}

function getPrompt() {
rl.question("word ", answer => {
console.log(pigLatin(answer));
getPrompt();
});
}

function handleTranslate() {
console.log("I am inside handleTranslate()");

//1. get the input value from the inputbox
var inputBox = document.getElementById("plainText");
console.log(inputBox);
var englishWord = inputBox.value;
console.log("english word", englishWord);

//2. call the pigLatin function with this value
var pigLatinWord = pigLatin(englishWord);
console.log("pig latin word ", pigLatinWord);
//3. write teh result that the piglatinfunction returns to the screen
var spanElement = document.getElementById("pigLatinText");
console.log("span element", spanElement);
spanElement.innerText = pigLatinWord;
}

// Tests

if (typeof describe === "function") {
describe("#pigLatin()", () => {
it("should translate a simple word", () => {
assert.equal(pigLatin("car"), "arcay");
assert.equal(pigLatin("dog"), "ogday");
});
it("should translate a complex word", () => {
assert.equal(pigLatin("create"), "eatecray");
assert.equal(pigLatin("valley"), "alleyvay");
});
it('should attach "yay" if word begins with vowel', () => {
assert.equal(pigLatin("egg"), "eggyay");
assert.equal(pigLatin("emission"), "emissionyay");
});
it("should lowercase and trim word before translation", () => {
assert.equal(pigLatin("HeLlO "), "ellohay");
assert.equal(pigLatin(" RoCkEt"), "ocketray");
});
});
} else {
getPrompt();
}
78 changes: 78 additions & 0 deletions 03week/rockPaperScissors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"use strict";

const assert = require("assert");
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

function rockPaperScissors(hand1, hand2) {
// Write code here
hand1 = hand1.trim().toLowerCase();
hand2 = hand2.trim().toLowerCase();

if (hand1 === hand2) {
return "It's a tie!";
}

if (hand1 === "rock" && hand2 === "scissors") {
return "Hand one wins!";
}

if (hand1 === "rock" && hand2 === "paper") {
return "Hand two wins!";
}

if (hand1 === "paper" && hand2 === "rock") {
return "Hand one wins!";
}

if (hand1 === "paper" && hand2 === "scissors") {
return "Hand two wins!";
}

if (hand1 === "scissors" && hand2 === "paper") {
return "Hand one wins!";
}

if (hand1 === "scissors" && hand2 === "rock") {
return "Hand two wins!";
}
}

function getPrompt() {
rl.question("hand1: ", answer1 => {
rl.question("hand2: ", answer2 => {
console.log(rockPaperScissors(answer1, answer2));
getPrompt();
});
});
}

// Tests

if (typeof describe === "function") {
describe("#rockPaperScissors()", () => {
it("should detect a tie", () => {
assert.equal(rockPaperScissors("rock", "rock"), "It's a tie!");
assert.equal(rockPaperScissors("paper", "paper"), "It's a tie!");
assert.equal(rockPaperScissors("scissors", "scissors"), "It's a tie!");
});
it("should detect which hand won", () => {
assert.equal(rockPaperScissors("rock", "paper"), "Hand two wins!");
assert.equal(rockPaperScissors("rock", "scissors"), "Hand one wins!");
assert.equal(rockPaperScissors("paper", "scissors"), "Hand two wins!");
assert.equal(rockPaperScissors("paper", "rock"), "Hand one wins!");
assert.equal(rockPaperScissors("scissors", "rock"), "Hand two wins!");
assert.equal(rockPaperScissors("scissors", "paper"), "Hand one wins!");
});
it('should scrub input to ensure lowercase with "trim"ed whitepace', () => {
assert.equal(rockPaperScissors("rOcK", " paper "), "Hand two wins!");
assert.equal(rockPaperScissors("Paper", "SCISSORS"), "Hand two wins!");
assert.equal(rockPaperScissors("rock ", "sCiSsOrs"), "Hand one wins!");
});
});
} else {
getPrompt();
}
Loading