Last active
April 28, 2020 00:35
-
-
Save djds23/a191e27e6ec0ae4baab6d70326e8fa2d to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
The answers to each of these questions should be written as a function. | |
Call the function to execute your code. | |
Open this file in a text editor like "Sublime Text" or "Notepad++" | |
Write your answers in this file, saving often. | |
Copy & paste your code into the sandbox in order to run it & test that it works | |
Sandbox: https://eloquentjavascript.net/code/ | |
_Reminder_ | |
Writing a function looks like one of these: | |
const exampleArrow = (a, b) => { | |
// your code here | |
}; | |
exampleArrow(1, 2); // call the function | |
const exampleWithFunctionKeyword = function(a, b) => { | |
// your code here | |
}; | |
exampleWithFunctionKeyword(1, 2) // call the function | |
function exampleDeclaration(a, b) { | |
// your code here | |
}; | |
exampleDeclaration(1, 2); // call the function | |
*/ | |
/* | |
Exercise 1) | |
Write a function named `countToTen` that when called, | |
prints out the numbers 0-10. | |
*/ | |
countToTen(); | |
/* | |
Exercise 2) | |
Write a function named `countToN` that takes an argument of a number, | |
and counts from zero to that number, printing each number along the way. | |
For example: | |
countToN(100); // should print 0 to 100 | |
*/ | |
countToN(100); | |
/* | |
Exercise 3) | |
Write a function named `countToNByStep` that takes two arguments, each of a number. | |
This function counts from zero to that number, stepping by the second argument. | |
For example: | |
countToNByStep(10, 2); // should print 0, 2, 4, 6, 8, 10 | |
*/ | |
countToNByStep(10, 2); | |
/* | |
Exercise 4) | |
Write a function named `stringFromZeroToN` that takes one argument. | |
This function returns a string containing all the numbers from zero to that number, | |
separated by a `,`. The final number should not contain a `,`. | |
For example: | |
stringFromZeroToN(5); // returns "0, 1, 2, 3, 4, 5" | |
*/ | |
console.log(stringFromZeroToN(5)); | |
/* | |
Exercises 5) | |
Write a function named `isSentence` that takes an argument of a string, | |
and returns true if that string has a period (.) in it. | |
For example: | |
isSentence("Machines can read english."); // returns true | |
isSentence("This is an incomplete"); // returns false | |
Hints: | |
* You can check the length of a string by calling `.length` on it | |
* You can get individual characters from a string by using the `[]` with an index, starting at 0 for the first character | |
- example: "dean"[0] is d | |
- example: "dean"[3] is n | |
* You return from a function with the `return` keyword | |
*/ | |
console.log(isSentence("Machines can read english.")); | |
console.log(isSentence("This is an incomplete")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment