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
2 changes: 2 additions & 0 deletions 01week/datatypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,7 @@ if(!(a>0 && b>0)){
console.log ('Lies');
}

yea



1 change: 1 addition & 0 deletions 01week/rockPaperScissors.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ if (typeof describe === "function") {
} else {
getPrompt();
}
yea;
82 changes: 45 additions & 37 deletions 02week/pigLatin.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,59 @@
'use strict';
"use strict";

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


function pigLatin(word) {

// Your code here

word = word.trim().toLowerCase();
const vowels = ["a", "e", "i", "o", "u"];
let vowelIndex = 0;
if (vowels.includes(word[0])) {
return word + "yay";
} else {
for (let char of word) {
if (vowels.includes(char)) {
vowelIndex = word.indexOf(char);
break;
}
}
return word.slice(vowelIndex) + word.slice(0, vowelIndex) + "ay";
}
}


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

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

getPrompt();
}

//testing
24 changes: 24 additions & 0 deletions 02week/pigLatinGUI/pigLatins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use strict";

function pigLatin() {
let newWord = document.getElementById("enterhere").value;
newWord = newWord.trim().toLowerCase();
const vowels = ["a", "e", "i", "o", "u"];

let vowelIndex = 0;
let finish;

if (vowels.includes(newWord[0])) {
finish = newWord + "yay";
} else {
for (let char of newWord) {
if (vowels.includes(char)) {
vowelIndex = newWord.indexOf(char);
break;
}
}

finish = newWord.slice(vowelIndex) + newWord.slice(0, vowelIndex) + "ay";
}
document.getElementById("output").innerHTML = finish;
}
Loading