finish JavaScript and OOP sections for QA
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
{
|
||||
"id":"cf1111c1c15feddfaeb1bdef",
|
||||
"title": "Declare JavaScript Objects as Variables",
|
||||
"difficulty":0,
|
||||
"description":[
|
||||
"Before we dive into Object Oriented Programming, let's revisit JavaScript objects.",
|
||||
"Give your <code>motorBike</code> object a <code>wheels</code>, <code>engines</code> and <code>seats</code> attribute and set them to numbers."
|
||||
@@ -26,21 +25,20 @@
|
||||
"assert(typeof(motorBike.seats) === 'number', 'message: <code>motorBike</code> should have a <code>seats</code> attribute set to a number.');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"//Here is a sample Object",
|
||||
"var car = {",
|
||||
" \"wheels\":4,",
|
||||
" \"engines\":1,",
|
||||
" \"seats\":5",
|
||||
"};",
|
||||
"",
|
||||
"//Now Let's make a similar Object called motorBike",
|
||||
"//Give it two wheels, one engine and one seat",
|
||||
"var motorBike = {",
|
||||
"",
|
||||
" // Only change code below this line.",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
" // Only change code above this line.",
|
||||
"",
|
||||
"};",
|
||||
"",
|
||||
"(function() {return JSON.stringify(motorBike);})();"
|
||||
@@ -52,9 +50,14 @@
|
||||
{
|
||||
"id":"cf1111c1c15feddfaeb2bdef",
|
||||
"title": "Construct JavaScript Objects with Functions",
|
||||
"difficulty":0,
|
||||
"description":[
|
||||
"We are also able to create objects using <code>constructor</code> functions.",
|
||||
"Here's an example of a constructor function:",
|
||||
"<code>var Car = function() {</code>",
|
||||
"<code>  this.wheels = 4;</code>",
|
||||
"<code>  this.engines = 1;</code>",
|
||||
"<code>  this.seats = 1;</code>",
|
||||
"<code>};</code>",
|
||||
"Give your <code>myMotorBike</code> object a <code>wheels</code>, <code>engines</code> and <code>seats</code> attribute and set them to numbers."
|
||||
],
|
||||
"tests":[
|
||||
@@ -63,7 +66,6 @@
|
||||
"assert(typeof((new MotorBike()).seats) === 'number', 'message: <code>myMotorBike</code> should have a <code>seats</code> attribute set to a number.');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"// Let's add the properties engines and seats to the car in the same way that the property wheels has been added below. They should both be numbers.",
|
||||
"var Car = function() {",
|
||||
" this.wheels = 4;",
|
||||
" this.engines = 1;",
|
||||
@@ -73,6 +75,7 @@
|
||||
"var myCar = new Car();",
|
||||
"",
|
||||
"// Only change code below this line.",
|
||||
"",
|
||||
"var MotorBike = function() {",
|
||||
"",
|
||||
"",
|
||||
@@ -80,6 +83,7 @@
|
||||
"};",
|
||||
"",
|
||||
"var myMotorBike = new MotorBike();",
|
||||
"",
|
||||
"// Only change code above this line.",
|
||||
"",
|
||||
"(function() {return JSON.stringify(myMotorBike);})();"
|
||||
@@ -90,12 +94,12 @@
|
||||
{
|
||||
"id":"cf1111c1c15feddfaeb3bdef",
|
||||
"title":"Make Object Properties Private",
|
||||
"difficulty":0,
|
||||
"description":[
|
||||
"Objects have their own attributes, called <code>properties</code>, and their own functions, called <code>methods</code>.",
|
||||
"In the previous challenge, we used the <code>this</code> keyword to reference <code>public properties</code> and <code>public methods</code> of the current object.",
|
||||
"We can also create <code>private properties</code> and <code>private methods</code>, which aren't accessible from outside the object.",
|
||||
"To do this, we omit the word <code>this</code> from the <code>property</code> or <code>method</code> declaration.",
|
||||
"Let's create an object with two functions. One attached as a property and one not.",
|
||||
"See if you can keep <code>myBike.speed</code> and <code>myBike.addUnit</code> private, while making <code>myBike.getSpeed</code> publicly accessible."
|
||||
],
|
||||
"tests":[
|
||||
@@ -104,7 +108,6 @@
|
||||
"assert(typeof(myBike.addUnit) === 'undefined', 'message: <code>myBike.addUnit</code> should remain undefined.');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"//Let's create an object with two functions. One attached as a property and one not.",
|
||||
"var Car = function() {",
|
||||
" this.gear = 1;",
|
||||
" function addStyle(styleMe){",
|
||||
@@ -116,7 +119,9 @@
|
||||
"};",
|
||||
"",
|
||||
"var Bike = function() {",
|
||||
"",
|
||||
" // Only change code below this line.",
|
||||
"",
|
||||
" this.speed = 100;",
|
||||
" function addUnit(value) {",
|
||||
" return value + \"KM/H\";",
|
||||
@@ -125,11 +130,13 @@
|
||||
" getSpeed = function () {",
|
||||
" return addUnit(speed);",
|
||||
" };",
|
||||
" ",
|
||||
"",
|
||||
"};",
|
||||
"",
|
||||
"// Only change code above this line.",
|
||||
"",
|
||||
"var myCar = new Car();",
|
||||
"",
|
||||
"var myBike = new Bike();",
|
||||
"",
|
||||
"if(myBike.hasOwnProperty('getSpeed')){(function() {return JSON.stringify(myBike.getSpeed());})();};"
|
||||
@@ -140,7 +147,6 @@
|
||||
{
|
||||
"id":"cf1111c1c15feddfaeb4bdef",
|
||||
"title":"Make Instances of Objects with a Constructor Function",
|
||||
"difficulty":0,
|
||||
"description":[
|
||||
"Sometimes you'll want to be able to easily create similar objects.",
|
||||
"Objects have their own attributes, called <code>properties</code>, and their own functions, called <code>methods</code>.",
|
||||
@@ -164,7 +170,6 @@
|
||||
"// Only change code below this line.",
|
||||
"var myCar = new Car();",
|
||||
"",
|
||||
"//Add the property \"engines\" to myCar, and make it a number.",
|
||||
"",
|
||||
"",
|
||||
"// Only change code above this line.",
|
||||
@@ -176,7 +181,6 @@
|
||||
{
|
||||
"id":"cf1111c1c15feddfaeb7bdef",
|
||||
"title":"Iterate over Arrays with .map",
|
||||
"difficulty":0,
|
||||
"description":[
|
||||
"The map method is one of the easiest ways to iterate through an array or object there is. Let's use it now.",
|
||||
"<code>array = array.map(function(val){</code>",
|
||||
@@ -191,13 +195,14 @@
|
||||
"assert(editor.getValue().match(/\\[1\\,2\\,3\\,4\\,5\\]/gi), 'message: You should only modify the array with <code>.map</code>.');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"//Use map to add three to each value in the array",
|
||||
"var array = [1,2,3,4,5];",
|
||||
"",
|
||||
"// Only change code below this line.",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"// Only change code above this line.",
|
||||
"",
|
||||
"(function() {return array;})();"
|
||||
],
|
||||
"MDNlinks":[
|
||||
@@ -209,7 +214,6 @@
|
||||
{
|
||||
"id":"cf1111c1c15feddfaeb8bdef",
|
||||
"title":"Condense arrays with .reduce",
|
||||
"difficulty":0,
|
||||
"description":[
|
||||
"Reduce can be useful for condensing an array of numbers into one value.",
|
||||
"<code>var singleVal = array.reduce(function(previousVal, currentVal){</code>",
|
||||
@@ -223,12 +227,15 @@
|
||||
],
|
||||
"challengeSeed":[
|
||||
"var array = [4,5,6,7,8];",
|
||||
"",
|
||||
"var singleVal = 0;",
|
||||
"",
|
||||
"// Only change code below this line.",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"// Only change code above this line.",
|
||||
"",
|
||||
"(function() {return singleVal;})();"
|
||||
],
|
||||
"MDNlinks":[
|
||||
@@ -240,7 +247,6 @@
|
||||
{
|
||||
"id":"cf1111c1c15feddfaeb9bdef",
|
||||
"title":"Filter Arrays with .filter",
|
||||
"difficulty":0,
|
||||
"description":[
|
||||
"Filter is a useful method that can filter out values that don't match a certain criteria",
|
||||
"Let's remove all the values greater than five",
|
||||
@@ -255,11 +261,13 @@
|
||||
],
|
||||
"challengeSeed":[
|
||||
"var array = [1,2,3,4,5,6,7,8,9,10];",
|
||||
" // Only change code below this line.",
|
||||
"",
|
||||
"// Only change code below this line.",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
" // Only change code above this line.",
|
||||
"// Only change code above this line.",
|
||||
"",
|
||||
"(function() {return array;})();"
|
||||
],
|
||||
"MDNlinks":[
|
||||
@@ -271,7 +279,6 @@
|
||||
{
|
||||
"id":"cf1111c1c16feddfaeb1bdef",
|
||||
"title": "Sort Arrays with .sort",
|
||||
"difficulty":0,
|
||||
"description":[
|
||||
"You can use the method <code>sort</code> to easily sort the values in the array alphabetically or numerically.",
|
||||
"<code>var array = [1, 3, 2];</code>",
|
||||
@@ -286,11 +293,13 @@
|
||||
],
|
||||
"challengeSeed":[
|
||||
"var array = ['beta', 'alpha', 'charlie'];",
|
||||
"",
|
||||
"// Only change code below this line.",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
" // Only change code above this line.",
|
||||
"// Only change code above this line.",
|
||||
"",
|
||||
"(function() {return array;})();"
|
||||
],
|
||||
"MDNlinks":[
|
||||
@@ -313,11 +322,13 @@
|
||||
],
|
||||
"challengeSeed": [
|
||||
"var array = [1,2,3,4,5,6,7];",
|
||||
" // Only change code below this line.",
|
||||
"",
|
||||
"// Only change code below this line.",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
" // Only change code above this line.",
|
||||
"// Only change code above this line.",
|
||||
"",
|
||||
"(function() {return array;})();"
|
||||
],
|
||||
"MDNlinks":[
|
||||
@@ -343,11 +354,13 @@
|
||||
"var array = [1,2,3];",
|
||||
"",
|
||||
"var concatMe = [4,5,6];",
|
||||
"",
|
||||
"// Only change code below this line.",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"// Only change code above this line.",
|
||||
"",
|
||||
"(function() {return array;})();"
|
||||
],
|
||||
"MDNlinks":[
|
||||
@@ -359,7 +372,6 @@
|
||||
{
|
||||
"id":"cf1111c1c16feddfaeb4bdef",
|
||||
"title":"Split Strings with .split",
|
||||
"difficulty":0,
|
||||
"description":[
|
||||
"You can use the <code>.split()</code> method to split a string into an array.",
|
||||
"<code>.split()</code> uses the argument you pass in as a delimiter to determine which points the string should be split at.",
|
||||
@@ -367,16 +379,18 @@
|
||||
"Use <code>.split()</code> to create an array of words from <code>string</code> and assign it to <code>array</code>."
|
||||
],
|
||||
"tests":[
|
||||
"assert(typeof(array) === 'object' && array.length === 5, 'message: You should split the string by its spaces.');",
|
||||
"assert(/\\.split\\(/gi, 'message: You should use the split method on the string.');"
|
||||
"assert(/\\.split\\(/gi, 'message: You should use the split method on the string.');",
|
||||
"assert(typeof(array) === 'object' && array.length === 5, 'message: You should split the string by its spaces.');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"var string = \"Split me into an array\";",
|
||||
"",
|
||||
"// Only change code below this line.",
|
||||
"",
|
||||
"var array = string;",
|
||||
"",
|
||||
"// Only change code above this line.",
|
||||
"",
|
||||
"(function() {return array;})();"
|
||||
],
|
||||
"MDNlinks":[
|
||||
@@ -388,7 +402,6 @@
|
||||
{
|
||||
"id":"cf1111c1c16feddfaeb5bdef",
|
||||
"title":"Join Strings with .join",
|
||||
"difficulty":0,
|
||||
"description":[
|
||||
"We can use the <code>.join()</code> method to join each element in an array into a string separated by whatever delimiter you provide as an argument to the join operation.",
|
||||
"<code>var joinMe = joinMe.join(\" \");</code>",
|
||||
@@ -400,11 +413,13 @@
|
||||
],
|
||||
"challengeSeed":[
|
||||
"var joinMe = [\"Split\",\"me\",\"into\",\"an\",\"array\"];",
|
||||
"",
|
||||
"// Only change code below this line.",
|
||||
"",
|
||||
"joinMe = joinMe;",
|
||||
"",
|
||||
"// Only change code above this line.",
|
||||
"",
|
||||
"(function() {return joinMe;})();"
|
||||
],
|
||||
"MDNlinks":[
|
||||
|
Reference in New Issue
Block a user