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
114 changes: 114 additions & 0 deletions 01week/datatypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
'use strict';

// This is test #1 - return the current date
function currentDate() {
return Date();
}

console.log('Test 1');
console.log(currentDate());
console.log('');

// Test #2 - convert number to string.
function numberToString (theNumber) {
if (typeof theNumber === 'number') {
return theNumber.toString();
} else {
return 'Please pass a number';
}
}

console.log('Test 2');
console.log(numberToString(28)); // positive test
console.log(numberToString('Hello')); // negative test
console.log('');


// Test #3 - convert string to a number.
function stringToNumber (theString) {
return parseInt(theString);
}

console.log('Test 3');
console.log(stringToNumber('17')); // positive test
console.log(stringToNumber('84 apples')); // positive test
console.log(stringToNumber('apple 24')); // negative test
console.log('');


// Test #4 - display datatypes
function displayDataTypes(theArg, runParseInt = false) {
if (runParseInt) {
return parseInt(theArg);
} else if (theArg === '') {
return null;
} else {
return typeof theArg;
}
}

console.log('Test 4');
console.log(displayDataTypes(false)); // boolean
console.log(displayDataTypes('')); // null
let myUndefined;
console.log(displayDataTypes(myUndefined)); // undefined
console.log(displayDataTypes(42)); // number
console.log(displayDataTypes('I am a string', true)); // NaN
console.log(displayDataTypes('I am a string')); // string
console.log('');


// Test #5 - Add two numbers
function add(number1, number2) {
if (typeof number1 === 'number' && typeof number2 === 'number') {
return number1 + number2;
} else {
return 'Please try again and provide two numbers'
}
}

console.log('Test 5');
console.log(add(28, 34)); // positive test
console.log(add('4', '8')); // negative test
console.log('');


// test #6 - tests if 2 things are true
function twoThingsTrue(expr1, expr2) {
if (expr1 && expr2) {
return 'TWO THINGS ARE TRUE: Executing code inside conditional statement';
}
return 'Nothing happened';
}

console.log('Test 6');
console.log(twoThingsTrue(5<6, 7<8)); // positive test
console.log(twoThingsTrue(5<6, 7>8)); // negative test
console.log('');

// test #7 - tests if at least one thing is true
function oneThingTrue(expr1, expr2) {
if (expr1 || expr2) {
return 'AT LEAST ONE THING IS TRUE: Executing code inside conditional statement';
}
return 'Nothing happened';
}

console.log('Test 7');
console.log(oneThingTrue(5<6, 7>8)); // positive test
console.log(oneThingTrue(5>6, 7>8)); // negative test

console.log('');


// test #8 - tests if neither thing is true
function neitherThingTrue(expr1, expr2) {
if (!expr1 && !expr2) {
return 'NEITHER THING IS TRUE: Executing code inside conditional statement';
}
return 'Nothing happened';
}

console.log('Test 8');
console.log(neitherThingTrue(5>6, 7>8)); // positive test
console.log(neitherThingTrue(5<6, 7>8)); // negative test
30 changes: 30 additions & 0 deletions 01week/hungerGames.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

/*
* Pick a random student from this class
*
* Store names in a variable - array
*
* generate a random number, less than amount in class
*
* apply the index to the array
*
* from that array, pick a random name
*
* return a name
*/

const classArray = ['Cameron', 'Craig', 'Trevor', 'Ty', 'Ryan'];

function genRanNum(max, min) {
return Math.floor(Math.random() * (1 + max - min) ) + min;
}
console.log(genRanNum(5,0));

function genRanName() {
const index = genRanNum(classArray.length - 1, 0);
console.log(index);
return classArray[index];

}
console.log(genRanName());
1 change: 0 additions & 1 deletion 01week/javascripting/introduction.js

This file was deleted.

35 changes: 33 additions & 2 deletions 02week/pigLatin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,41 @@ const rl = readline.createInterface({

function pigLatin(word) {

// Your code here
// First, define vowels array
// Turn string into array
// Compare each character to the vowels array.
// if first letter AND vowel, add yay to end of string and return.
// else if nth letter is vowel, add ay to string array and return.
// else if nth letter is consonant, remove from front and move to end of array.
// When returning, turn string array string back into a string

}
// NOTE: This code only handles words that contain a traditional vowel. Does not work for words using y as a vowel.
// such as: sky, fly, why, try

word = word.toLowerCase().trim();
let wordArray = word.split('');

// This piece of code tests if the current letter is a vowel or not
const isAVowel = (letter) => {
const vowelsArr = ['a','e','i','o','u']
return vowelsArr.some(vowel => letter === vowel);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice method!

}

// The while loop tests the current letter for a vowel. If not, then move the consonant to the end.
// If it finds a vowel, then break.
let counter = 0;
while (!isAVowel(wordArray[0])) {
wordArray.push(wordArray.shift()); // This should move first char to last.
counter++;
}

// This code adds either ay or yay at the end to complete the piglatin conversion.
if (counter === 0) {
return wordArray.join('')+'yay';
} else {
return wordArray.join('')+'ay';
}
}

function getPrompt() {
rl.question('word ', (answer) => {
Expand Down
Loading