Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JMCR-Complete Skill-sharpening-project #247

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
42 changes: 32 additions & 10 deletions src/01-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
* alwaysTrue();
* //> true
*/
function alwaysTrue() {}
function alwaysTrue() {
return true
}

/**
* greet()
Expand All @@ -24,7 +26,9 @@ function alwaysTrue() {}
* greet("Ian");
* //> "Hello, Ian."
*/
function greet() {}
function greet(name) {
return `Hello, ${name}.`
}

/**
* add()
Expand All @@ -39,7 +43,9 @@ function greet() {}
* add(10, 20);
* //> 30
*/
function add() {}
function add(a, b) {
return a + b
}

/**
* multiply()
Expand All @@ -54,7 +60,9 @@ function add() {}
* multiply(2, 5);
* //> 10
*/
function multiply() {}
function multiply(a, b) {
return a * b
}

/**
* average()
Expand All @@ -74,7 +82,9 @@ function multiply() {}
* average(10, 6);
* //> 8 // 10 + 6 = 16; 16/2 = 8;
*/
function average() {}
function average(a, b) {
return (a + b) / 2
}

/**
* averageThree()
Expand All @@ -93,7 +103,9 @@ function average() {}
* averageThree(10, 11, 19);
* //> 10 // 10 + 11 + 19 = 30; 30 / 3 = 10;
*/
function averageThree() {}
function averageThree(a, b, c) {
return (a + b + c) / 3
}

/**
* compareTypes()
Expand All @@ -112,7 +124,11 @@ function averageThree() {}
* compareTypes("left", 10);
* //> false
*/
function compareTypes() {}
function compareTypes(a, b) {
if (typeof(a) === typeof(b))
return true
else return false
}

/**
* flipSign()
Expand All @@ -131,7 +147,9 @@ function compareTypes() {}
* flipSign(50);
* //> -50
*/
function flipSign() {}
function flipSign(a) {
return -a
}

/**
* joinStringsWithSpaces()
Expand All @@ -151,7 +169,9 @@ function flipSign() {}
* joinStringsWithSpaces("left", "right", "up", "down", "away");
* //> "left right up down away"
*/
function joinStringsWithSpaces() {}
function joinStringsWithSpaces(a, b, c, d, e) {
return `${a} ${b} ${c} ${d} ${e}`
}

/**
* getFirstAndLastCharacter()
Expand All @@ -168,7 +188,9 @@ function joinStringsWithSpaces() {}
* getFirstAndLastCharacter("upwards");
* //> "us"
*/
function getFirstAndLastCharacter() {}
function getFirstAndLastCharacter(a) {
return `${a.charAt(0)}${a.charAt(a.length -1)}`
}

// Do not change the code below.
module.exports = {
Expand Down
56 changes: 46 additions & 10 deletions src/02-data-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
* getLengthOfString("down");
* //> 4
*/
function getLengthOfString(str) {}
function getLengthOfString(str) {
return str.length
}

/**
* convertToNumber()
Expand All @@ -22,7 +24,9 @@ function getLengthOfString(str) {}
* convertToNumber("111");
* //> 111
*/
function convertToNumber(val) {}
function convertToNumber(val) {
return parseInt(val)
}

/**
* convertToString()
Expand All @@ -36,7 +40,9 @@ function convertToNumber(val) {}
* convertToString(99);
* //> "99"
*/
function convertToString(val) {}
function convertToString(val) {
return String(val)
}

/**
* convertToShoutingText()
Expand All @@ -49,7 +55,9 @@ function convertToString(val) {}
* convertToShoutingText("Hello There");
* //> "HELLO THERE"
*/
function convertToShoutingText(text) {}
function convertToShoutingText(text) {
return text.toUpperCase()
}

/**
* convertToWhisperText()
Expand All @@ -62,7 +70,9 @@ function convertToShoutingText(text) {}
* convertToWhisperText("Hello There");
* //> "hello there"
*/
function convertToWhisperText(text) {}
function convertToWhisperText(text) {
return text.toLowerCase()
}

/**
* checkIfCharacterIsInString()
Expand All @@ -79,7 +89,13 @@ function convertToWhisperText(text) {}
* checkIfCharacterIsInString("hello there", "a");
* //> false
*/
function checkIfCharacterIsInString(text, character) {}
function checkIfCharacterIsInString(text, character) {
// if (text === character){
// return true
// } else if (text !== character)
// return false
return text.includes(character)
}

/**
* isEven()
Expand All @@ -95,7 +111,9 @@ function checkIfCharacterIsInString(text, character) {}
* isEven(11);
* //> false
*/
function isEven(num) {}
function isEven(num) {
return (num % 2 === 0)
}

/**
* isOdd()
Expand All @@ -111,7 +129,13 @@ function isEven(num) {}
* isOdd(11);
* //> true
*/
function isOdd(num) {}
function isOdd(num) {
if (num % 2 === 0) {
return false;
} else {
return true;
}
}

/**
* isTruthy()
Expand All @@ -127,7 +151,13 @@ function isOdd(num) {}
* isTruthy(null);
* //> false
*/
function isTruthy(val) {}
function isTruthy(val) {
if (!!val == false){
return false;
} else {
return true;
}
}

/**
* isFalsy()
Expand All @@ -143,7 +173,13 @@ function isTruthy(val) {}
* isFalsy(" ");
* //> false
*/
function isFalsy(val) {}
function isFalsy(val) {
if (!val == true){
return true;
} else {
return false;
}
}

// Do not change the code below.
module.exports = {
Expand Down
83 changes: 73 additions & 10 deletions src/03-control-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
* isEqual(10, "10");
* //> false
*/
function isEqual(a, b) {}
function isEqual(a, b) {
return a ===b
}

/**
* findLarger()
Expand All @@ -28,7 +30,9 @@ function isEqual(a, b) {}
* findLarger(19, 7);
* //> 19
*/
function findLarger(a, b) {}
function findLarger(a, b) {
return Math.max(a , b)
}

/**
* findLargerOrTie()
Expand All @@ -45,7 +49,15 @@ function findLarger(a, b) {}
* findLargerOrTie(0, 0);
* //> "tie"
*/
function findLargerOrTie(a, b) {}
function findLargerOrTie(a, b) {
if (Math.max(a) > Math.max(b)) {
return a
} else if(Math.max(a) < Math.max(b)) {
return b
} else {
return "tie"
}
}

/**
* positiveNegativeOrZero()
Expand All @@ -65,7 +77,16 @@ function findLargerOrTie(a, b) {}
* positiveNegativeOrZero(1);
* //> "Positive"
*/
function positiveNegativeOrZero(a) {}
function positiveNegativeOrZero(a) {
let i = 0
if (i > a) {
return "Negative"
} else if(i < a) {
return "Positive"
} else {
return "Zero"
}
}

/**
* aroundTheWorldGreeting()
Expand All @@ -86,7 +107,13 @@ function positiveNegativeOrZero(a) {}
* aroundTheWorldGreeting();
* //> "Hello World"
*/
function aroundTheWorldGreeting(language) {}
function aroundTheWorldGreeting(language) {
if (language == `spanish`){
return `Hola Mundo`
} else if(language == `german`){
return `Hallo Welt`
} else return `Hello World`
}

/**
* aroundTheWorldGreetingWithSwitch()
Expand All @@ -109,7 +136,21 @@ function aroundTheWorldGreeting(language) {}
* aroundTheWorldGreetingWithSwitch();
* //> "Hello World"
*/
function aroundTheWorldGreetingWithSwitch(language) {}
function aroundTheWorldGreetingWithSwitch(language) {
let myDefault = "Hello World"

switch (language){
case "english":
myDefault = "Hello World";
break;
case "spanish":
myDefault = "Hola Mundo";
break;
case "german":
myDefault = "Hallo Welt";
break;
} return myDefault
}

/**
* calculateLetterGrade()
Expand All @@ -128,7 +169,19 @@ function aroundTheWorldGreetingWithSwitch(language) {}
* calculateLetterGrade(99);
* //> "A"
*/
function calculateLetterGrade(grade) {}
function calculateLetterGrade(grade) {
if (grade >= 90){
return "A"
} else if (grade >= 80){
return "B"
} else if (grade >= 70){
return "C"
} else if (grade >= 60){
return "D"
} else if (grade >= 60){
return "E"
} else return "F"
}

/**
* animalCounts()
Expand All @@ -146,7 +199,11 @@ function calculateLetterGrade(grade) {}
* animalCounts("pig", 1);
* //> "1 pig"
*/
function animalCounts(animal, numberOfAnimals) {}
function animalCounts(animal, numberOfAnimals) {
if (numberOfAnimals > 1){
return `${numberOfAnimals} ${animal}s`
} else return `${numberOfAnimals} ${animal}`
}

/**
* evenOrOdd()
Expand All @@ -163,7 +220,11 @@ function animalCounts(animal, numberOfAnimals) {}
* evenOrOdd(48);
* //> "Even"
*/
function evenOrOdd(a) {}
function evenOrOdd(a) {
if (a % 2 === 0){
return `Even`
} else return "Odd"
}

/**
* evenOrOddWithTernary()
Expand All @@ -179,7 +240,9 @@ function evenOrOdd(a) {}
* evenOrOddWithTernary(8);
* //> "Even"
*/
function evenOrOddWithTernary(a) {}
function evenOrOddWithTernary(a) {
return (a % 2 === 0 ? 'Even' : 'Odd');
}

// Do not change any code below this line.
module.exports = {
Expand Down
Loading