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

function myAge( ageNow, numYears ) {
function myAge( ageNow, numYears ){
const futureAge = numYears + ageNow

if (futureAge > 100){
return NaN
}
else if(typeof ageNow !== "number" || typeof numYears !== "number" || numYears < 0 || ageNow < 0){
return -1
}
else{
return futureAge
}
}

}
console.log(typeof 44)

console.log(myAge(-1, 92))



Expand All @@ -30,10 +44,16 @@ Concatenating string variables
******************/

function myConcatenate( firstStr, secondStr, thirdStr ) {
const mySentence = firstStr + secondStr + thirdStr
console.log(mySentence)
return mySentence


}

myConcatenate('I', 'am', 'iron man'); // 'I am iron man'


console.log(myConcatenate('I ', 'am ', 'iron man ')); // 'I am iron man'

/******************
Subtract Function
Expand All @@ -45,9 +65,15 @@ Ensure that both of the inputs are numbers
******************/

function subtract(a,b) {
const diff = a - b
if(typeof a != "number" || typeof b != "number"){
console.log("Input Numbers Only")
} else {
return diff
}

}

console.log(subtract("why",200))
/******************
Area of A Circle

Expand All @@ -62,8 +88,10 @@ A = π * r2, where is π is Pi and r is the radius squared

function areaOfaCircle(radius){


const A = 3.14 * radius**2
return A
}
console.log(areaOfaCircle(5))

/******************
Temperature Converter Fahrenheit to Celsius
Expand All @@ -74,8 +102,13 @@ Now store a fahrenheit temperature into a variable.

Convert it to celsius and output "NN°F is NN°C."
******************/
function fahrenheitToCelsius(fahr){

const fToC = (fahr - 32) * 5/9
return fToC

}
console.log(fahrenheitToCelsius(32))
/******************
Temperature Converter Celsius to Fahrenheit

Expand All @@ -85,7 +118,13 @@ Store a celsius temperature into a variable.

Convert it to fahrenheit and output "NN°C is NN°F".
******************/
function CelsiusToFahrenheit(cels){

const cToF = (cels * 5/9) + 32
return cToF

}
console.log(CelsiusToFahrenheit(32))

/******************
Is it the weekend?
Expand All @@ -103,8 +142,17 @@ 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){
const dayOfWeek = day
if (dayOfWeek === "Saturday" || dayOfWeek ==="Sunday"){
console.log("Yes, it's the Weekend ")
}
else{
console.log("No, it's the weekday")
}
return 1
}
console.log(isItTheWeekend("Sunday"))
/******************
Finding the absolute value of a number

Expand All @@ -115,6 +163,20 @@ 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){
if(num >= 0){
return num
}
else {

return num * -1

}

}
console.log(absolute(10))




/******************
Expand All @@ -128,4 +190,18 @@ return the number of characters in the string
call function 'countChars'
******************/

function countChars(str){
if(typeof str !== "string"){

console.log("Input letters")

return "Input letters"
}

else {

return str.length
}
}

console.log(countChars("daniel"))
5 changes: 5 additions & 0 deletions pset2.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
returns that computed value
@example doMath( 1,2,3 ); // 9
*/
function doMath(firstNum, secondNum, thirdNum){

const arith = (firstNum + secondNum) * thirdNum
return arith
}
console.log(doMath(1,2,3))

/*
@function addMiddleName
Expand Down