Sunday, July 15, 2018

Basic JavaScript: Stand in Line

In Computer Science a queue is an abstract Data Structure where items are kept in order. New items can be added at the back of the queueand old items are taken off from the front of the queue.
Write a function nextInLinewhich takes an array (arr) and a number (item) as arguments.
Add the number to the end of the array, then remove the first element of the array.
The nextInLinefunction should then return the element that was removed.

Saturday, July 14, 2018

Basic JavaScript: Understanding Undefined Value returned from a Function

Create a function addFive without any arguments. This function adds 5 to the sum variable, but its returned value is undefined.

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

Basic JavaScript: Local Scope and Functions

Declare a local variable myVar inside myLocalScope. Run the tests and then follow the instructions commented out in the editor.

Hint
Refreshing the page may help if you get stuck.


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

Basic JavaScript: Appending Variables to Strings

Just as we can build a string over multiple lines out of string literals, we can also append variables to a string using the plus equals (+=) operator.


Set someAdjective and append it to myStr using the += operator.


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.

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.
CodeOutput
\'single quote
\"double quote
\\backslash
\nnewline
\rcarriage return
\ttab
\bbackspace
\fform 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.
FirstLine newlinetabbackslash SecondLinenewline ThirdLine

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

D26 Basic #JavaScript: Compound Assignment With Augmented Multiplication


The *=operator multiplies a variable by a number.
myVar = myVar * 5;
will multiply myVarby 5. This can be rewritten as:
myVar *= 5;


Convert the assignments for ab, and cto use the *=operator.

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");