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
+
+a
to variable b
.
+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));
+```
+
+=
).
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
.
7
to variable a
.
-Assign the contents of a
to variable b
.
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') {