forked from AustinCodingAcademy/javascript-workbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Class3functions #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
renataestes
wants to merge
5
commits into
gh-pages
Choose a base branch
from
class3functions
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 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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,95 @@ | ||
| 'use strict'; | ||
|
|
||
| /** | ||
| - write a function for current date and time | ||
| - wite a function to convert a number to a string | ||
| - write a function to convert a string to a number | ||
| - write a function that takes in different datatypes and prints out what they are | ||
| - write a function that adds 2 numbers together | ||
| - write a function that only runs when 2 things are true | ||
| - write a function that runs when 1 of 2 things are true | ||
| - write a function when both things are NOT true | ||
| **/ | ||
|
|
||
| //Current Date & Time | ||
| function returnDate() { | ||
| let now = new Date(); | ||
| return now; | ||
| } | ||
| console.log( returnDate()); | ||
|
|
||
|
|
||
| //Convert # to String | ||
| function numToString(x) { | ||
| return x.toString(); | ||
| } | ||
| numToString(17); | ||
|
|
||
|
|
||
| //Convert a String to # | ||
| function stringToNum(x) { | ||
| let a = parseInt(x); | ||
| console.log(a); | ||
| return a; | ||
| } | ||
| stringToNum('5'); | ||
|
|
||
|
|
||
| //Different datatypes | ||
| function typeOf(datatype) { | ||
| return typeof datatype; | ||
| } | ||
| console.log(typeof false); | ||
| console.log(typeof null); | ||
| console.log(typeof myLife); | ||
| console.log(typeof 1.08); | ||
| console.log(typeof NaN); | ||
| console.log(typeof "I love JS!"); | ||
| typeOf(5); | ||
|
|
||
|
|
||
| //Add 2 #s | ||
| function addition(x, y) { | ||
| console.log(x + y); | ||
| return x + y; | ||
| } | ||
| addition(5,5); | ||
|
|
||
|
|
||
| //Two things are true | ||
| function theTruth() { | ||
| if (9 > 8 && 8 > 7) { | ||
| console.log("Numbers never lie!"); | ||
| return true; | ||
| } else { | ||
| console.log("Numbers aren't the source of truth."); | ||
| return false; | ||
| } | ||
| } | ||
| theTruth(); | ||
|
|
||
|
|
||
| //One of two things are true | ||
| function theTruth() { | ||
| if (9 > 8 && 9 > 10) { | ||
| console.log("Nine is the greatest number!"); | ||
| return true; | ||
| } else { | ||
| console.log("Nine is only greater than eight."); | ||
| return false; | ||
| } | ||
| } | ||
| theTruth(); | ||
|
|
||
|
|
||
| //Both not true | ||
| function theTruth() { | ||
| if (9 === 8 && 8 === 7) { | ||
| console.log("Numbers never lie!"); | ||
| return true; | ||
| } else { | ||
| console.log("Numbers aren't the source of truth after all."); | ||
| return false; | ||
| } | ||
| } | ||
| theTruth(); |
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 var, pick a random names | ||
| * | ||
| * return a name | ||
| **/ | ||
|
|
||
| const studentArray = ['Ryan', 'Renata', 'Trevor'] | ||
|
|
||
| function randomNumberInRange(top, bottom) { | ||
| return Math.floor(Math.random() * (top - bottom + 1)) + bottom; //The maximum is inclusive and the minimum is inclusive | ||
| } | ||
|
|
||
| console.log(randomNumberInRange(2,0)); | ||
|
|
||
| function generateRandomName() { | ||
| const index = randomNumberInRange(studentArray.length -1, 0); | ||
| return studentArray[index]; | ||
| } | ||
|
|
||
| console.log(generateRandomName); |
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
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
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.
don't use var, use const or let