diff --git a/01week/datatypes.js b/01week/datatypes.js index e69de29bb..32d5b0291 100644 --- a/01week/datatypes.js +++ b/01week/datatypes.js @@ -0,0 +1,51 @@ +// 1.Write a JavaScript program to display the current day and time. +let date = new Date(); +console.log(date); +"/n" +// 2. Write a JavaScript program to convert a number to a string. +let number2 = 15; +number2 = "This is now a string" +console.log(number2); + +//3. Write a JavaScript program to convert a string to the number. +let string3 = 'String'; +string3= 4; +console.log(string3); + +//4. Write a JavaScript program that takes in different datatypes and prints out whether they are a: +//Boolean +console.log(typeof true); +//Null +console.log(typeof null); +//Undefined +console.log(typeof x); +//Number +console.log(typeof 4); +//NaN +console.log(typeof NaN); +//String +console.log(typeof 'Hello World!'); + +//5.Write a JavaScript program that adds 2 numbers together. +let sum = (2+2); +console.log(sum); + + +//6.Write a JavaScript program that runs only when 2 things are true + +let firstStatement = true; +let secondStatement = true; +if (firstStatement && secondStatement){ + console.log('Both are true'); +} + +//7.Write a JavaScript program that runs when 1 of 2 things are true. + +if (firstStatement || secondStatement){ + console.log("At least one is true"); +} + +//8.Write a JavaScript program that runs when both things are not true +if (!firstStatement && !secondStatement ){ + console.log('Both are false') +} \ No newline at end of file diff --git a/01week/rockPaperScissors.js b/01week/rockPaperScissors.js index 16f58790a..41f578742 100644 --- a/01week/rockPaperScissors.js +++ b/01week/rockPaperScissors.js @@ -8,9 +8,86 @@ const rl = readline.createInterface({ }); -function rockPaperScissors(hand1, hand2) { +function rockPaperScissors(userOne, userTwo) { - // Write code here + + //User1 input of rock, paper, or scissors. +let userOne = "paper" +function userOneChoice(userOne) { + userOne.toLocaleLowerCase(); + if (userOne === 'rock' || userOne === 'paper' || userOne === 'scissors'){ + console.log('User 1 threw ' + userOne) + } else { + console.log('This is not an acceptable value!') + } +}; +userOneChoice(userOne); + + +//User2 input of rock, paper, or scissors. +let userTwo = "rock" +function userTwoChoice(userTwo) { + userOne.toLocaleLowerCase(); + if (userTwo === 'rock' || userTwo === 'paper' || userTwo === 'scissors'){ + console.log('User 2 threw ' + userTwo) + } else { + console.log('This is not an acceptable value!') + } +}; +userTwoChoice(userTwo); + + +//Compare User1 input to User2 input. +function determineWinner (userOne,userTwo){ + + + //If User1 input is 'rock' and User2 input is 'scissor', User1 wins. + if(userOne === 'rock' && userTwo === 'scissors'){ + console.log('User1 wins!') + }; + + //If User1 input is 'rock' and User2 input is 'paper', User2 wins. + if (userOne === 'rock' && userTwo === 'paper'){ + console.log('User2 wins!') + }; + + //If User1 input is 'rock' and User2 input is 'rock', it's a tie. + if (userOne === 'rock' && userTwo === 'rock'){ + console.log("It's a tie.") + }; + + //If User1 input is 'paper' and User2 input is 'rock', User1 wins. + if (userOne === 'paper' && userTwo === 'rock'){ + console.log('User1 wins!') + }; + + //If User1 input is 'paper' and User2 input is 'scissors', User2 wins. + if (userOne === 'paper' && userTwo === 'scissors'){ + console.log('User2 wins!') + }; + + //If User1 input is 'paper' and User2 input is 'paper', it's a tie. + if (userOne === 'paper' && userTwo === 'paper'){ + console.log("It's a tie.") + }; + + //If User1 input is 'scissors' and User2 input is 'paper', User1 wins. + if (userOne === 'scissors' && userTwo === 'paper'){ + console.log('User1 wins!') + }; + + //If User1 input is 'scissors' and User2 input is 'rock', User2 wins. + if (userOne === 'scissors' && userTwo === 'rock'){ + console.log('User 2 wins!') + }; + + //If User1 input is 'scissors' and User2 input is 'scissors', it's a tie. + if (userOne === 'scissors' && userTwo === 'scissors'){ + console.log("It's a tie.") + }; +}; + +determineWinner(userOne,userTwo); } diff --git a/02week/pigLatin.js b/02week/pigLatin.js index 046434c94..bcfeda321 100644 --- a/02week/pigLatin.js +++ b/02week/pigLatin.js @@ -9,12 +9,18 @@ const rl = readline.createInterface({ function pigLatin(word) { - - // Your code here - + for (i =0; i < word.length; i++) { + let y = ""; + if ( word.charAt(0)=="a" || word.charAt(0)=="e" || word.charAt(0)=="i" || word.charAt(0)=="o" || word.charAt(0)=="u"){ + y = word + "ay"; + return y; + } else if (word.charAt(i)=="a" || word.charAt(i)=="e" || word.charAt(i)=="i" || word.charAt(i)=="o" || word.charAt(i)=="u"){ + y=word.slice(i)+word.slice(0,i) + "ay"; + return y; + } + } } - function getPrompt() { rl.question('word ', (answer) => { console.log( pigLatin(answer) );