forked from AustinCodingAcademy/javascript-workbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Week2a piglatin #3
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
Open
copelandhouse2
wants to merge
3
commits into
gh-pages
Choose a base branch
from
week2a-piglatin
base: gh-pages
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| 'use strict'; | ||
|
|
||
| // This is test #1 - return the current date | ||
| function currentDate() { | ||
| return Date(); | ||
| } | ||
|
|
||
| console.log('Test 1'); | ||
| console.log(currentDate()); | ||
| console.log(''); | ||
|
|
||
| // Test #2 - convert number to string. | ||
| function numberToString (theNumber) { | ||
| if (typeof theNumber === 'number') { | ||
| return theNumber.toString(); | ||
| } else { | ||
| return 'Please pass a number'; | ||
| } | ||
| } | ||
|
|
||
| console.log('Test 2'); | ||
| console.log(numberToString(28)); // positive test | ||
| console.log(numberToString('Hello')); // negative test | ||
| console.log(''); | ||
|
|
||
|
|
||
| // Test #3 - convert string to a number. | ||
| function stringToNumber (theString) { | ||
| return parseInt(theString); | ||
| } | ||
|
|
||
| console.log('Test 3'); | ||
| console.log(stringToNumber('17')); // positive test | ||
| console.log(stringToNumber('84 apples')); // positive test | ||
| console.log(stringToNumber('apple 24')); // negative test | ||
| console.log(''); | ||
|
|
||
|
|
||
| // Test #4 - display datatypes | ||
| function displayDataTypes(theArg, runParseInt = false) { | ||
| if (runParseInt) { | ||
| return parseInt(theArg); | ||
| } else if (theArg === '') { | ||
| return null; | ||
| } else { | ||
| return typeof theArg; | ||
| } | ||
| } | ||
|
|
||
| console.log('Test 4'); | ||
| console.log(displayDataTypes(false)); // boolean | ||
| console.log(displayDataTypes('')); // null | ||
| let myUndefined; | ||
| console.log(displayDataTypes(myUndefined)); // undefined | ||
| console.log(displayDataTypes(42)); // number | ||
| console.log(displayDataTypes('I am a string', true)); // NaN | ||
| console.log(displayDataTypes('I am a string')); // string | ||
| console.log(''); | ||
|
|
||
|
|
||
| // Test #5 - Add two numbers | ||
| function add(number1, number2) { | ||
| if (typeof number1 === 'number' && typeof number2 === 'number') { | ||
| return number1 + number2; | ||
| } else { | ||
| return 'Please try again and provide two numbers' | ||
| } | ||
| } | ||
|
|
||
| console.log('Test 5'); | ||
| console.log(add(28, 34)); // positive test | ||
| console.log(add('4', '8')); // negative test | ||
| console.log(''); | ||
|
|
||
|
|
||
| // test #6 - tests if 2 things are true | ||
| function twoThingsTrue(expr1, expr2) { | ||
| if (expr1 && expr2) { | ||
| return 'TWO THINGS ARE TRUE: Executing code inside conditional statement'; | ||
| } | ||
| return 'Nothing happened'; | ||
| } | ||
|
|
||
| console.log('Test 6'); | ||
| console.log(twoThingsTrue(5<6, 7<8)); // positive test | ||
| console.log(twoThingsTrue(5<6, 7>8)); // negative test | ||
| console.log(''); | ||
|
|
||
| // test #7 - tests if at least one thing is true | ||
| function oneThingTrue(expr1, expr2) { | ||
| if (expr1 || expr2) { | ||
| return 'AT LEAST ONE THING IS TRUE: Executing code inside conditional statement'; | ||
| } | ||
| return 'Nothing happened'; | ||
| } | ||
|
|
||
| console.log('Test 7'); | ||
| console.log(oneThingTrue(5<6, 7>8)); // positive test | ||
| console.log(oneThingTrue(5>6, 7>8)); // negative test | ||
|
|
||
| console.log(''); | ||
|
|
||
|
|
||
| // test #8 - tests if neither thing is true | ||
| function neitherThingTrue(expr1, expr2) { | ||
| if (!expr1 && !expr2) { | ||
| return 'NEITHER THING IS TRUE: Executing code inside conditional statement'; | ||
| } | ||
| return 'Nothing happened'; | ||
| } | ||
|
|
||
| console.log('Test 8'); | ||
| console.log(neitherThingTrue(5>6, 7>8)); // positive test | ||
| console.log(neitherThingTrue(5<6, 7>8)); // negative test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| 'use strict'; | ||
|
|
||
| /* | ||
| * Pick a random student from this class | ||
| * | ||
| * Store names in a variable - array | ||
| * | ||
| * generate a random number, less than amount in class | ||
| * | ||
| * apply the index to the array | ||
| * | ||
| * from that array, pick a random name | ||
| * | ||
| * return a name | ||
| */ | ||
|
|
||
| const classArray = ['Cameron', 'Craig', 'Trevor', 'Ty', 'Ryan']; | ||
|
|
||
| function genRanNum(max, min) { | ||
| return Math.floor(Math.random() * (1 + max - min) ) + min; | ||
| } | ||
| console.log(genRanNum(5,0)); | ||
|
|
||
| function genRanName() { | ||
| const index = genRanNum(classArray.length - 1, 0); | ||
| console.log(index); | ||
| return classArray[index]; | ||
|
|
||
| } | ||
| console.log(genRanName()); |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice method!