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
78 changes: 78 additions & 0 deletions 01week/datatypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//1. Write a JavaScript program to display the current day and time.
function findTime(){
const now = new Date(); //find date
const date = (now.getMonth() + 1) + "/" + now.getDate(); //display month/day
const time = now.getHours() + ":" + now.getMinutes(); //display hour:minute
const dayArray = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; //array for day of the week
const day = dayArray[now.getDay()]; //get string day of week
const dateTime = "It is " + day + ", " + date + " at " + time + "."; //display time and date in string
return dateTime;
}
findTime()

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

function numToString(num){
return num.toString();
}
numToString(30)


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

function stringToNum(string){
return Number(string);
}
stringToNum('89')


//4. Write a JavaScript program that takes in different datatypes and prints out what type they are.

function dataType(type){
return typeof(type);
}
dataType('eklgjheoh')


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

function sumNumbers (num1,num2) {
return num1 + num2
}
sumNumbers(7, 3000)

//6. Write a JavaScript program that runs only when 2 things are true.

function bothTrue (arg1, arg2) {
if(arg1 && arg2) {
return 'both are true'
}else{
return 'nope'
}
}
bothTrue(4, 6);
bothTrue(null, 6);

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

function oneTrueThing(arg1, arg2) {
if (arg1 || arg2) {
return "one argument is true";
} else {
return "Neither is true";
}
}
oneTrueThing(true, false)
oneTrueThing(false, true)

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

function bothFalse(arg1, arg2) {
if (!arg1 && !arg2) {
return "both are false"
} else {
return "at least one argument is true"
}
}
bothFalse(null, null)
bothFalse(0, 5)
39 changes: 38 additions & 1 deletion 01week/rockPaperScissors.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,50 @@ const rl = readline.createInterface({
output: process.stdout
});

// an easier way to do this would have been if (hand1 === hand2) {
//return 'its a tie!';
//}

function rockPaperScissors(hand1, hand2) {

Choose a reason for hiding this comment

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

This pull request has two files in it For now we're only working on one file at a time. Please make sure your PR have only one file.


// Write code here
hand1=hand1.toLowerCase().trim();
hand2=hand2.toLowerCase().trim();

if (hand1 === 'rock'){
if (hand2 === 'rock') {
return "It's a tie!";
}else if (hand2 === 'paper'){
return "Hand two wins!";
}else if (hand2 === 'scissors') {
return "Hand one wins!";
}else {
return "try again";
}
}else if (hand1 === 'paper') {
if (hand2 === 'rock') {
return "Hand one wins!";
}else if (hand2 === 'paper') {
return "It's a tie!";
}else if (hand2 === 'scissors') {
return "Hand two wins!";
}else {
return "try again";
}

}else if (hand1 === 'scissors') {
if (hand2 === 'rock') {
return "Hand two wins!";
}else if (hand2 === 'paper'){
return "Hand one wins!";
} else if(hand2 === 'scissors') {
return "It's a tie!";
}else {
return "try again";
}
}
}


function getPrompt() {
rl.question('hand1: ', (answer1) => {
rl.question('hand2: ', (answer2) => {
Expand Down