-
Notifications
You must be signed in to change notification settings - Fork 0
Class3 functions #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
base: gh-pages
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| 'use strict'; | ||
|
|
||
| /** | ||
| * pick a ronadom 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 one | ||
| * | ||
| * return a name | ||
| * */ | ||
|
|
||
| const studentArray = []; | ||
|
|
||
| function randomNumberInRange (top, bottom){ | ||
| return Math.floor( Math.random() * ( 1 + top - bottom ) ) + bottom; | ||
| } | ||
|
|
||
| console.log(randomNumberInRange(14, 0)); | ||
| function generateRandomName() { | ||
| const index = randomNumberInRange(studentArray.length -1, 0); | ||
| return studentArray[index]; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,78 @@ | ||
| console.log('hello'); | ||
| 'use strict'; | ||
|
|
||
| // Write a JavaScript program to display the current day and time. | ||
|
|
||
| function currentDateTime(){ | ||
| return(new Date()); | ||
| } | ||
| console.log(currentDateTime(); | ||
|
|
||
|
|
||
| // Write a JavaScript program to convert a number to a string. | ||
|
|
||
| function numberToString(num){ | ||
| console.log(num.toString()); | ||
| } | ||
| return numberToString(10); | ||
|
|
||
|
|
||
|
|
||
| // Write a JavaScript program to convert a string to the number. | ||
|
|
||
| function stringToNumber(number){ | ||
| console.log(parseInt(number)); | ||
| } | ||
| return stringToNumber(224); | ||
|
|
||
|
|
||
| // Write a JavaScript program that takes in different datatypes and prints out whether they are a: | ||
| // Boolean | ||
| // Null | ||
| // Undefined | ||
| // Number | ||
| // NaN | ||
| // String | ||
|
|
||
| function ReturnType(someData){ | ||
| console.log(typeof someData); | ||
| } | ||
| ReturnType('Hello'); | ||
| ReturnType(10); | ||
| ReturnType(); | ||
| ReturnType(true); | ||
| ReturnType(0/0); | ||
|
|
||
|
|
||
| // Write a JavaScript program that adds 2 numbers together. | ||
|
|
||
| function addingStuff(dig1, dig2){ | ||
| console.log( dig1 + dig2 ); | ||
| } | ||
| addingStuff(4, 7); | ||
|
|
||
| // Write a JavaScript program that runs only when 2 things are true. | ||
| function trueTings (x, y){ | ||
| if(x === true && y === true) { | ||
| console.log("It's True!"); | ||
| } | ||
| } | ||
| trueTings(true,true); | ||
|
|
||
|
|
||
| // Write a JavaScript program that runs when 1 of 2 things are true. | ||
|
|
||
| function oneTingTrue (z, p) { | ||
| if (p || z === true) { | ||
| console.log("There can only be one"); | ||
| } | ||
| } | ||
| oneTingTrue(true, true); | ||
|
|
||
| // Write a JavaScript program that runs when both things are not true. | ||
|
|
||
| function noTrueTings (w, r) { | ||
| if (w != 2 && r != 13){ | ||
| console.log("Yeah right! Neither are true"); | ||
| } | ||
| } | ||
| noTrueTings(true, true); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,13 +11,45 @@ const rl = readline.createInterface({ | |
| function pigLatin(word) { | ||
|
|
||
| // Your code here | ||
| // Array will be the word argument as an array | ||
| var array = word.split(''); | ||
|
|
||
| // Vowels going to test against | ||
| var vowels = ['a', 'e', 'i', 'o', 'u']; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't use var, use const or let depending if you're going to re-assign. |
||
|
|
||
| // Create newWord var to hold reordered letters | ||
| var newWord = ''; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't use var, use const or let depending if you're going to re-assign. |
||
|
|
||
| // Loop through leters in word | ||
| for (var y = 0; y < word.length - 1; y++) { | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think of a way to only use one loop. 2 loops are unnecessary. |
||
| // Loop through vowels | ||
| for (var i = 0; i < vowels.length - 1; i++) { | ||
|
|
||
|
|
||
| // If any letter in word matches a letter in vowwels | ||
| if (word[y] === vowels[i]) { | ||
|
|
||
|
|
||
| for (var x = y; x < word.length; x++) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explain to me why you are using so many loops? |
||
| newWord = newWord + word[x]; | ||
| } | ||
| for (var n = 0; n < y; n++) { | ||
| newWord = newWord + word[n]; | ||
| } | ||
| return newWord + "ay"; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| translate("goat"); | ||
|
|
||
|
|
||
|
|
||
| function getPrompt() { | ||
| rl.question('word ', (answer) => { | ||
| console.log( pigLatin(answer) ); | ||
| console.log(pigLatin(answer)); | ||
| getPrompt(); | ||
| }); | ||
| } | ||
|
|
||
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 depending if you're going to re-assign.