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

/**
* pick a ronadom 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 one
*
* return a name
* */

const studentArray = [];

function randomNumberInRange (top, bottom){
return Math.floor( Math.random() * ( 1 + top - bottom ) ) + bottom;
}

console.log(randomNumberInRange(14, 0));
function generateRandomName() {
const index = randomNumberInRange(studentArray.length -1, 0);
return studentArray[index];
}
79 changes: 78 additions & 1 deletion 01week/javascripting/introduction.js
Original file line number Diff line number Diff line change
@@ -1 +1,78 @@
console.log('hello');
'use strict';

// Write a JavaScript program to display the current day and time.

function currentDateTime(){
return(new Date());
}
console.log(currentDateTime();


// Write a JavaScript program to convert a number to a string.

function numberToString(num){
console.log(num.toString());
}
return numberToString(10);



// Write a JavaScript program to convert a string to the number.

function stringToNumber(number){
console.log(parseInt(number));
}
return stringToNumber(224);


// Write a JavaScript program that takes in different datatypes and prints out whether they are a:
// Boolean
// Null
// Undefined
// Number
// NaN
// String

function ReturnType(someData){
console.log(typeof someData);
}
ReturnType('Hello');
ReturnType(10);
ReturnType();
ReturnType(true);
ReturnType(0/0);


// Write a JavaScript program that adds 2 numbers together.

function addingStuff(dig1, dig2){
console.log( dig1 + dig2 );
}
addingStuff(4, 7);

// Write a JavaScript program that runs only when 2 things are true.
function trueTings (x, y){
if(x === true && y === true) {
console.log("It's True!");
}
}
trueTings(true,true);


// Write a JavaScript program that runs when 1 of 2 things are true.

function oneTingTrue (z, p) {
if (p || z === true) {
console.log("There can only be one");
}
}
oneTingTrue(true, true);

// Write a JavaScript program that runs when both things are not true.

function noTrueTings (w, r) {
if (w != 2 && r != 13){
console.log("Yeah right! Neither are true");
}
}
noTrueTings(true, true);
31 changes: 29 additions & 2 deletions 01week/rockPaperScissors.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,44 @@ const rl = readline.createInterface({
output: process.stdout
});

// My Code

function rockPaperScissors(hand1, hand2) {

// Write code here
if (hand1 === hand2) {
return "It's a tie!";

} else if (hand1 === "Rock") {

if (hand2 === "Paper") {
return "Hand 2 wins with Paper!";
} else {
return "Hand 1 wins with Rock";
}

} else if (hand1 === "Paper") {

if (hand2 === "Rock") {
return "Hand 1 wins with Paper!";
} else {
return "Hand 2 wins with Scissors";
}

} else(hand1 === "Scissors"); {

}
if (hand2 === "Rock") {
return "Hand 2 wins with Rock!";
} else {
return "Hand one with Scissors";
}

}

function getPrompt() {
rl.question('hand1: ', (answer1) => {
rl.question('hand2: ', (answer2) => {
console.log( rockPaperScissors(answer1, answer2) );
console.log(rockPaperScissors(answer1, answer2));
getPrompt();
});
});
Expand Down
106 changes: 106 additions & 0 deletions 02week/arrayprjtct1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
'use strict';

// length
// Create an array called cars which consists of 4 different types of cars. The first car type should be Ford.
// Console.log the length of the array.
let cars = [
'Toyota',
'Ford',
'Audi',
'VW'
];
console.log(cars.length);


// concat
// Create another array called more cars with 4 more different types of cars. The last car type should be Honda.
// Use the concat method to combine the cars and moreCars arrays into an array called totalCars.
let moreCars = [
'BMW',
'Ferrari',
'Mercedez',
'Honda'
];
let totalCars = cars.concat(moreCars);
console.log(totalCars);


// indexOf and lastIndexOf
// Use the indexOf method to console.log the index of Honda.
// Use the lastIndexOf method to console.log the index of Ford.
console.log(totalCars.indexOf('Honda'));
console.log(totalCars.lastIndexOf('Ford'));

// join
// Use the join method to covert the array totalCars into a string called stringOfCars.
let stringOfCars = totalCars.join();
console.log(stringOfCars);


// split
// Use the split method to convert stringOfCars back intro an array called totalCars.
let totalCars2 = stringOfCars.split();
console.log(totalCars2);


// reverse
// Use the reverse method to create an array carsInReverse which is the array totalCars in reverse.
let carsInReverse = totalCars.reverse();
console.log(carsInReverse);
// An array of strings that is turned into a singular string, then turned back into an array is no longer an array of strings.
// Therefore we used the 1st array 'totalCars' of strings



// sort
// Use the sort method to put the array carsInReverse into alphabetical order.
// Based on the types of cars you used, predict which item in the array should be at index 0.
// Use the following code to confirm or reject your prediction:
// alert(carsInReverse.indexOf('yourPrediction'));
let alphaCars = carsInReverse.sort();
console.log(alphaCars);
alert(carsInReverse.indexOf('BMW'));


// slice
// Use the slice method to remove Ford and Honda from the carsInReverse array and move them into a new array called removedCars.
let removedCars = alphaCars.slice(3,5);
console.log(removedCars);


// splice
// Use the splice method to remove the 2nd and 3rd items in the array carsInReverse and add Ford and Honda in their place.
let carsSpliced = alphaCars.splice(1,2,"Ford", "Honda");
console.log(carsSpliced);
console.log(alphaCars);

// push
// Use the push method to add the types of cars that you removed using the splice method to the carsInReverse array.
let joinedCars = alphaCars.push('BMW', 'Ferrari');
console.log(joinedCars);
console.log(alphaCars);

// pop
// Use the pop method to remove and console.log the last item in the array carsInReverse.
console.log(carsInReverse.pop());


// shift
// Use the shift method to remove and console.log the first item in the array carsInReverse.
console.log(carsInReverse.shift());


// unshift
// Use the unshift method to add a new type of car to the array carsInReverse.
console.log(carsInReverse.unshift('Acura'));
console.log(carsInReverse);


// forEach
// Create an array called numbers with the following items: 23, 45, 0, 2
// Write code that will add 2 to each item in the array numbers.
var numbers = [23, 45, 0 , 2];
function addTwo(item) {
console.log(item + 2);
}
numbers.forEach(addTwo)
96 changes: 68 additions & 28 deletions 02week/pigLatin.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,81 @@ const rl = readline.createInterface({
function pigLatin(word) {

// Your code here
// Declare pigLatin as a function and 'str' as a placeholder for a given string
const pigLatin = word => {

}
// Make a list of vowels to test each letter of str against
let vowels = ['a', 'e', 'i', 'o', 'u'];

// Turn the given string into an array and put it into 'result' var
let result = word.split('');

function getPrompt() {
rl.question('word ', (answer) => {
console.log( pigLatin(answer) );
getPrompt();
});
}
// If the vowels array includes the first indexed letter of str
if (vowels.includes(word[0])) {

// Tests
// Return the given string with 'yay' added at the end
return word += 'yay';

if (typeof describe === 'function') {
// The vowels array DOES NOT include the first indexed letter of str
} else {

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');
// Loop over each letter in the string given
for (let i = 0; i < word.length; i++) {

// Using the iterator declared above, test each letter in str
// If the iterator DOES NOT include a letter in the vowel array
if (!vowels.includes(word[i])) {

// Using str in array form, remove the first letter on the array, then add it to the end
result.push(result.shift());

// Once the iterator DOES match a letter in the vowel array
} else {

// Add 'ay' to the end of the str
result.push('ay');

// Turn the rearranged str (var result) back into a string and return it
return result.join('');
}
}
}
}




function getPrompt() {
rl.question('word ', (answer) => {
console.log(pigLatin(answer));
getPrompt();
});
it('should lowercase and trim word before translation', () => {
assert.equal(pigLatin('HeLlO '), 'ellohay');
assert.equal(pigLatin(' RoCkEt'), 'ocketray');
}

// 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 {
} else {

getPrompt();
getPrompt();

}
}
Loading