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
192 changes: 184 additions & 8 deletions pset1.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,34 @@ if that number is > 100, should return NaN
if invalid input given, return -1
******************/

function myAge( ageNow, numYears ) {

function myAge(ageNow = 26, numYears = 10) {
let sum = ageNow + numYears;
if (sum < 100) {
let string = `In ${numYears} years, I will be ${sum}`;
return string;
}
else if (sum > 100) {
return NaN;
}
else if ((typeof ageNow !== 'number') || (typeof numYears !== 'number')){
return -1;
}
}
console.log(myAge());

const myAge = function(ageNow, numYears) {
let sum = ageNow + numYears;
let string = `In ${numYears} years, I will be ${sum}`;
return string;
}
console.log(myAge());

const myAge = (ageNow, numYears) => {
let sum = ageNow + numYears;
let string = `In ${numYears} years, I will be ${sum}`;
return string;
}
console.log(myAge());

/******************
Concatenate Strings
Expand All @@ -29,11 +52,24 @@ Concatenating string variables
- Call myConcatenate function
******************/

function myConcatenate( firstStr, secondStr, thirdStr ) {

function myConcatenate( firstStr = 'I', secondStr = "am", thirdStr = "iron man" ) {
let mySentence = `${firstStr} ${secondStr} ${thirdStr}`;
return mySentence;
}
console.log(myConcatenate());

const myConcatenate = function(firstStr, secondStr, thirdStr) {
let mySentence = `${firstStr} ${secondStr} ${thirdStr}`;
return mySentence;
}
console.log(myConcatenate());

myConcatenate('I', 'am', 'iron man'); // 'I am iron man'
const myConcatenate = (firstStr, secondStr, thirdStr) => {
let mySentence = `${firstStr} ${secondStr} ${thirdStr}`;
return mySentence;
}
console.log(myConcatenate());
//myConcatenate('I', 'am', 'iron man'); // 'I am iron man'*/

/******************
Subtract Function
Expand All @@ -44,10 +80,18 @@ This function will take two numbers and subtract them
Ensure that both of the inputs are numbers
******************/

function subtract(a,b) {

function subtract(a = 0, b = 0) {
return a - b;
}
console.log(subtract());

const subtract = function(a = 0, b = 0) {
return a - b;
}
console.log(subtract());

const subtract = (a = 0, b = 0) => a - b;
console.log(subtract());
/******************
Area of A Circle

Expand All @@ -60,11 +104,20 @@ A = π * r2, where is π is Pi and r is the radius squared
******************/


function areaOfaCircle(radius){
function areaOfaCircle(radius = 1){
return Math.PI * (radius ** 2);

}
console.log(areaOfaCircle);

const area = function(radius = 1) {
return Math.PI * (radius ** 2);

}
console.log(areaOfaCircle);

const area = (radius = 1) => Math.PI * (radius ** 2);
console.log(area());
/******************
Temperature Converter Fahrenheit to Celsius

Expand All @@ -74,7 +127,28 @@ Now store a fahrenheit temperature into a variable.

Convert it to celsius and output "NN°F is NN°C."
******************/
function fahrenheitToCelsius(F = 32){
const C = ((F-32) * (5/9));
const fahrenheitToCelsius = `${F}°F is ${C}°C.`;
return fahrenheitToCelsius;
}
console.log(fahrenheitToCelsius());

const fahrenheitToCelsius = function(F = 32) {
const C = ((F-32) * (5/9));
const fahrenheitToCelsius = `${F}°F is ${C}°C.`;
return fahrenheitToCelsius;
}
console.log(fahrenheitToCelsius());

const fahrenheitToCelsius = (F = 32) => {
const C = ((F-32) * (5/9));
const fahrenheitToCelsius = `${F}°F is ${C}°C.`;
return fahrenheitToCelsius;
}
console.log(fahrenheitToCelsius());

/*

/******************
Temperature Converter Celsius to Fahrenheit
Expand All @@ -85,7 +159,26 @@ Store a celsius temperature into a variable.

Convert it to fahrenheit and output "NN°C is NN°F".
******************/
function celsiusToFahrenheit(C = 0){
let F = (C * 9/5) + 32;
const celsiusToFahrenheit = `${C}°C is ${F}°F.`;
return celsiusToFahrenheit;
}
console.log(celsiusToFahrenheit());

const celsiusToFahrenheit = function(C = 0) {
let F = (C * 9/5) + 32;
const celsiusToFahrenheit = `${C}°C is ${F}°F.`;
return celsiusToFahrenheit;
}
console.log(celsiusToFahrenheit());

const celsiusToFahrenheit = (C = 0) => {
let F = (C * 9/5) + 32;
const celsiusToFahrenheit = `${C}°C is ${F}°F.`;
return celsiusToFahrenheit;
}
console.log(celsiusToFahrenheit());

/******************
Is it the weekend?
Expand All @@ -103,7 +196,57 @@ console.log(today); // No, it's the weekday
If you are having trouble, please note that Javascript has a helpful built-in function to help get the current day
******************/

function isItTheWeekend(day) {

if (day === "Saturday") {
return 'Yes, it\'s the weekend';
}

else if (day === "Sunday") {
return 'Yes, it\'s the weekend';
}
else {
return 'No, it\'s the weekday';
}

}

console.log(today("Monday"));

const today = (day) => {

if (day === "Saturday") {
return 'Yes, it\'s the weekend';
}

else if (day === "Sunday") {
return 'Yes, it\'s the weekend';
}
else {
return 'No, it\'s the weekday';
}

}

console.log(today("Monday"));


const today = function isItTheWeekend(day) {

if (day === "Saturday") {
return 'Yes, it\'s the weekend';
}

else if (day === "Sunday") {
return 'Yes, it\'s the weekend';
}
else {
return 'No, it\'s the weekday';
}

}

console.log(today("Monday"));

/******************
Finding the absolute value of a number
Expand All @@ -115,7 +258,18 @@ The function should return the absolute value of the number
The absolute value of a negative number is the positive version of that same number,
and the absolute value of a positive number (or zero) is that number itself.
******************/
function absolute(num) {
return Math.abs(num);
}
console.log(absolute());

const absolute = function(num) {
return Math.abs(num);
}
console.log(absolute());

const absolute = (num = -1) => Math.abs(num);
console.log(absolute());

/******************
Create a function that counts the number of characters in your name
Expand All @@ -128,4 +282,26 @@ return the number of characters in the string
call function 'countChars'
******************/

function countChars(nameString = "Jane Doe") {
return nameString.length
}
console.log(countChars());

const countChars = function(nameString = "Jane Doe")) {
return nameString.length
}
console.log(countChars());

const countChar = (nameString = "Jane Doe")) => nameString.length;
console.log(countChars("Osita"));

const simpleConditionalExamples = () => {
if (true){
console.log('this will show up!');
}
if (false){
console.log('will this show up tho…?');
}
return 1;
}
simpleConditionalExamples();
36 changes: 27 additions & 9 deletions pset2.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
returns that computed value
@example doMath( 1,2,3 ); // 9
*/


const doMath = (firstNum, secondNum, thirdNum) => {
let sum = firstNum + secondNum;
let multiplies = sum * thirdNum;
return multiplies;
}
console.log(doMath( 1,2,3 ));
/*
@function addMiddleName
@param firstName
Expand All @@ -24,8 +28,14 @@
return firstname and last name
@example addMiddleNmae('John', 'Mabel', 'Smith'); // John Mabel Smith
*/


const addMiddleName = (firstName, lastName, middleName = "") =>{

if (middleName.length === 0) {
return firstName.concat(' ',lastName);
}
return firstName.concat(' ',middleName, ' ',lastName);
}
console.log(addMiddleName('John', 'Mabel','Smith'));
/*
@function defaultPlaceholder
@param placeholder {string}
Expand All @@ -35,8 +45,11 @@
@example defaultPlaceHolder('Hello Wrold!');
// <input type="text" placeholder="Hello Wrold!" />
*/


const defaultPlaceHolder = (placeholder = '') => {
const inputHolder = placeholder;
return `<input type="text" placeholder=${inputHolder} />`;
}
console.log(defaultPlaceHolder('Hello Wrold!'));
/*
@function addClasses
@param {string} class1
Expand All @@ -47,8 +60,10 @@
@example addClass('foo', 'bar', 'stuff');
// <div class="foo bar">stuff</div>
*/


const addClasses = (class1, class2, content) => {
return `<div class="${class1.concat(' ', class2)}">${content}/div>`;
}
console.log(addClasses('foo', 'bar', 'stuff'));
/*
@function duplicate
@param {string} start
Expand All @@ -58,4 +73,7 @@
@example duplicate('hello!'); // hello!hello!
*/


const duplicate = start => {
return start.concat(start);
}
console.log(duplicate('hello!'));
Loading