From f334734e98b2c6c5c23225c9a427975013d94c5a Mon Sep 17 00:00:00 2001 From: Beau Carnes <1513130+beaucarnes@users.noreply.github.com> Date: Mon, 31 Aug 2020 14:44:56 -0400 Subject: [PATCH] feat: split JS challenge into two (#39044) * feat: split JS challenge into two * fix/change-to-not-use-untaught-assignments Co-authored-by: moT01 <20648924+moT01@users.noreply.github.com> --- .../_meta/basic-javascript/meta.json | 4 + ...alue-of-one-variable-to-another.english.md | 105 ++++++++++++++++++ ...es-with-the-assignment-operator.english.md | 23 +--- 3 files changed, 115 insertions(+), 17 deletions(-) create mode 100644 curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/assigning-the-value-of-one-variable-to-another.english.md diff --git a/curriculum/challenges/_meta/basic-javascript/meta.json b/curriculum/challenges/_meta/basic-javascript/meta.json index 2e9185d571..e21172410a 100644 --- a/curriculum/challenges/_meta/basic-javascript/meta.json +++ b/curriculum/challenges/_meta/basic-javascript/meta.json @@ -20,6 +20,10 @@ "56533eb9ac21ba0edf2244a8", "Storing Values with the Assignment Operator" ], + [ + "5ee127a03c3b35dd45426493", + "Assigning the Value of One Variable to Another" + ], [ "56533eb9ac21ba0edf2244a9", "Initializing Variables with the Assignment Operator" diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/assigning-the-value-of-one-variable-to-another.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/assigning-the-value-of-one-variable-to-another.english.md new file mode 100644 index 0000000000..a57964bb0e --- /dev/null +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/assigning-the-value-of-one-variable-to-another.english.md @@ -0,0 +1,105 @@ +--- +id: 5ee127a03c3b35dd45426493 +title: Assigning the Value of One Variable to Another +challengeType: 1 +isHidden: false +videoUrl: '' +forumTopicId: 418265 +--- + +## Description + +
+After a value is assigned to a variable using the assignment operator, you can assign the value of that variable to another variable using the assignment operator. + +```js +var myVar; +myVar = 5; +var myNum; +myNum = myVar; +``` + +The above declares a `myVar` variable with no value, then assigns it the value `5`. Next, a variable named `myNum` is declared with no value. Then, the contents of `myVar` (which is `5`) is assigned to the variable `myNum`. Now, `myNum` also has the value of `5`. + +
+ +## Instructions + +
+Assign the contents of a to variable b. +
+ +## Tests + +
+ +```yml +tests: + - text: You should not change code above the specified comment. + testString: assert(/var a;/.test(code) && /a = 7;/.test(code) && /var b;/.test(code)); + - text: b should have a value of 7. + testString: assert(typeof b === 'number' && b === 7); + - text: a should be assigned to b with =. + testString: assert(/b\s*=\s*a\s*/g.test(code)); +``` + +
+ +## Challenge Seed + +
+ +
+ +```js +// Setup +var a; +a = 7; +var b; + +// Only change code below this line +``` + +
+ +### Before Test + +
+ +```js +if (typeof a != 'undefined') { + a = undefined; +} +if (typeof b != 'undefined') { + b = undefined; +} +``` + +
+ +### After Test + +
+ +```js +(function(a, b) { + return 'a = ' + a + ', b = ' + b; +})(a, b); +``` + +
+ +
+ +## Solution + +
+ +```js +var a; +a = 7; +var b; +b = a; +``` + +
diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/storing-values-with-the-assignment-operator.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/storing-values-with-the-assignment-operator.english.md index 732824e328..cbd55880d4 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/storing-values-with-the-assignment-operator.english.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/storing-values-with-the-assignment-operator.english.md @@ -9,23 +9,22 @@ forumTopicId: 18310 ## Description
-In JavaScript, you can store a value in a variable with the assignment operator. +In JavaScript, you can store a value in a variable with the assignment operator (=). myVariable = 5; This assigns the Number value 5 to myVariable. -Assignment always goes from right to left. Everything to the right of the = operator is resolved before the value is assigned to the variable to the left of the operator. +If there are any calculations to the right of the = operator, those are performed before the value is assigned to the variable on the left of the operator. ```js +var myVar; myVar = 5; -myNum = myVar; ``` -This assigns 5 to myVar and then resolves myVar to 5 again and assigns it to myNum. +First, this code creates a variable named myVar. Then, the code assigns 5 to myVar. Now, if myVar appears again in the code, the program will treat it as if it is 5.
## Instructions
Assign the value 7 to variable a. -Assign the contents of a to variable b.
## Tests @@ -34,13 +33,9 @@ Assign the contents of a to variable b. ```yml tests: - text: You should not change code above the specified comment. - testString: assert(/var a;/.test(code) && /var b = 2;/.test(code)); + testString: assert(/var a;/.test(code)); - text: a should have a value of 7. testString: assert(typeof a === 'number' && a === 7); - - text: b should have a value of 7. - testString: assert(typeof b === 'number' && b === 7); - - text: a should be assigned to b with =. - testString: assert(/b\s*=\s*a\s*;/g.test(code)); ``` @@ -54,7 +49,6 @@ tests: ```js // Setup var a; -var b = 2; // Only change code below this line @@ -69,9 +63,6 @@ var b = 2; if (typeof a != 'undefined') { a = undefined; } -if (typeof b != 'undefined') { - b = undefined; -} ``` @@ -80,7 +71,7 @@ if (typeof b != 'undefined') {
```js -(function(a,b){return "a = " + a + ", b = " + b;})(a,b); +(function(a){return "a = " + a;})(a); ```
@@ -93,9 +84,7 @@ if (typeof b != 'undefined') { ```js var a; -var b = 2; a = 7; -b = a; ```