Just my random coding struggles with some hip hop sprinkled in #vitalgroundz. While your here click a Ad or two.
Saturday, July 14, 2018
Thursday, July 12, 2018
Basic JavaScript: Return a Value from a Function with Return
We can pass values into a function with arguments. You can use a return statement to send a value back out of a function.
Example
function plusThree(num) {
return num + 3;
}
var answer = plusThree(5); // 8
plusThree takes an argument for num and returns a value equal to num + 3.
Create a function timesFive that accepts one argument, multiplies it by 5, and returns the new value. See the last line in the editor for an example of how you can test your timesFive function.
Wednesday, July 11, 2018
Tuesday, July 10, 2018
Basic JavaScript: Word Blanks
We will now use our knowledge of strings to build a "Mad Libs" style word game we're calling "Word Blanks". You will create an (optionally humorous) "Fill in the Blanks" style sentence.
In a "Mad Libs" game, you are provided sentences with some missing words, like nouns, verbs, adjectives and adverbs. You then fill in the missing pieces with words of your choice in a way that the completed sentence makes sense.
Consider this sentence - "It was really ____, and we ____ ourselves ____". This sentence has three missing pieces- an adjective, a verb and an adverb, and we can add words of our choice to complete it. We can then assign the completed sentence to a variable as follows:
var sentence = "It was really" + "hot" + ", and we" + "laughed" + "ourselves" + "silly.";
In this challenge, we provide you with a noun, a verb, an adjective and an adverb. You need to form a complete sentence using words of your choice, along with the words we provide.
You will need to use the string concatenation operator + to build a new string, using the provided variables: myNoun, myAdjective, myVerb, and myAdverb. You will then assign the formed string to the result variable.
You will also need to account for spaces in your string, so that the final sentence has spaces between all the words. The result should be a complete sentence.
Monday, July 9, 2018
Sunday, July 8, 2018
#100daysofcode D29 - Basic JavaScript: Concatenating Strings with Plus Operator
Basic JavaScript: Concatenating Strings with Plus Operator
In JavaScript, when the + operator is used with a String value, it is called the concatenation operator. You can build a new string out of other strings by concatenating them together.
Example
'My name is Alan,' + ' I concatenate.'
Note
Watch out for spaces. Concatenation does not add spaces between concatenated strings, so you'll need to add them yourself.
Build myStr from the strings "This is the start. " and "This is the end." using the + operator.
In JavaScript, when the + operator is used with a String value, it is called the concatenation operator. You can build a new string out of other strings by concatenating them together.
Example
'My name is Alan,' + ' I concatenate.'
Note
Watch out for spaces. Concatenation does not add spaces between concatenated strings, so you'll need to add them yourself.
Build myStr from the strings "This is the start. " and "This is the end." using the + operator.
Saturday, July 7, 2018
#100DAYSOFCODE D28 - Basic JavaScript: Escape Sequences in Strings
Quotes are not the only characters that can be escaped inside a string. There are two reasons to use escaping characters: First is to allow you to use characters you might not otherwise be able to type out, such as a backspace. Second is to allow you to represent multiple quotes in a string without JavaScript misinterpreting what you mean. We learned this in the previous challenge.
| Code | Output |
|---|---|
\' | single quote |
\" | double quote |
\\ | backslash |
\n | newline |
\r | carriage return |
\t | tab |
\b | backspace |
\f | form feed |
Note that the backslash itself must be escaped in order to display as a backslash.
Assign the following three lines of text into the single variable
myStrusing escape sequences.FirstLine
\SecondLine
ThirdLine
You will need to use escape sequences to insert special characters correctly. You will also need to follow the spacing as it looks above, with no spaces between escape sequences or words.
Here is the text with the escape sequences written out.
FirstLinenewlinetabbackslashSecondLinenewlineThirdLine
Friday, July 6, 2018
Escaping Literal Quotes in Strings: #100days of code D27
When you are defining a string you must start and end with a single or double quote. What happens when you need a literal quote:
"or 'inside of your string?
In JavaScript, you can escape a quote from considering it as an end of string quote by placing a backslash (
\) in front of the quote.var sampleStr = "Alan said, \"Peter is learning JavaScript\".";
This signals to JavaScript that the following quote is not the end of the string, but should instead appear inside the string. So if you were to print this to the console, you would get:
Alan said, "Peter is learning JavaScript".
Use backslashes to assign a string to the
myStrvariable so that if you were to print it to the console, you would see:I am a "double quoted" string inside "double quotes".Thursday, July 5, 2018
Monday, July 2, 2018
Sunday, December 17, 2017
Friday, September 15, 2017
#FreeCodeCamp Change Text with Click Events
#FreeCodeCamp Change Text with Click Events
When our click event happens, we can use jQuery to update an HTML element.
Let's make it so that when a user clicks the "Get Message" button, we change the text of the element with the class
message to say "Here is the message".
We can do this by adding the following code within our click event:
$(".message").html("Here is the message");Wednesday, August 9, 2017
Caesars Cipher
One of the simplest and most widely known ciphers is a
Caesar cipher, also known as a shift cipher. In a shift cipher the meanings of the letters are shifted by some set amount.
A common modern use is the ROT13 cipher, where the values of the letters are shifted by 13 places. Thus 'A' ↔ 'N', 'B' ↔ 'O' and so on.
Write a function which takes a ROT13 encoded string as input and returns a decoded string.
All letters will be uppercase. Do not transform any non-alphabetic character (i.e. spaces, punctuation), but do pass them on.
Subscribe to:
Posts (Atom)











