diff --git a/challenges/02-javascript-algorithms-and-data-structures/basic-javascript.json b/challenges/02-javascript-algorithms-and-data-structures/basic-javascript.json
index 9a868611b3..b594d83373 100755
--- a/challenges/02-javascript-algorithms-and-data-structures/basic-javascript.json
+++ b/challenges/02-javascript-algorithms-and-data-structures/basic-javascript.json
@@ -5585,65 +5585,31 @@
}
}
},
- {
- "id": "587d7b7e367417b2b2512b24",
- "title": "Use the Conditional Ternary Operator",
- "description": [
- "The conditional/ternary operator is a one line if-else statement.",
- "The syntax is",
- "condition ? statement-if-true : statement-if-false;
",
- "For example:",
- "function findGreater(a, b) {
",
- " if(a > b)
",
- " return \"a is greater\";
",
- " else
",
- " return \"b is greater\";
",
- "}
",
- "The above function can be written using the conditional like:",
- "function findGreater(a, b) {
",
- " return a > b ? \"a is greater\" : \"b is greater\";
",
- "}
",
- "Instructions",
- "Using a Conditional Operator, check if two numbers are equal or not."
- ],
- "challengeSeed": [
- "function checkEqual(a, b) {",
- "",
- "}",
- "checkEqual(1, 2);"
- ],
- "tail": [],
- "solutions": [],
- "tests": [
- "assert(checkEqual(1, 2) === false, 'message: checkEqual(1, 2)
should return false');",
- "assert(checkEqual(1, 1) === true, 'message: checkEqual(1, 1)
should return true');",
- "assert(checkEqual(1, -1) === false, 'message: checkEqual(1, -1)
should return false');"
- ],
- "type": "waypoint",
- "challengeType": 1,
- "translations": {}
- },
{
"id": "587d7b7e367417b2b2512b23",
- "title": "Use the parseInt function",
+ "title": "Use the parseInt Function",
"description": [
- "The parseInt() function parses a string and returns an integer.",
+ "The parseInt()
function parses a string and returns an integer. Here's an example:",
"var a = parseInt(\"007\");
",
- "The above function will convert the string \"007\" to an integer 7."
+ "The above function converts the string \"007\" to an integer 7. If the first character in the string can't be converted into a number, then it returns NaN
.",
+ "
parseInt()
in the convertToInteger
function so it converts the input string str
into an integer, and returns it."
],
"challengeSeed": [
"function convertToInteger(str) {",
- "",
+ " ",
"}",
+ "",
"convertToInteger(\"56\");"
],
"tail": [],
"solutions": [],
"tests": [
+ "assert(/parseInt/g.test(code), 'message: convertToInteger
should use the parseInt()
function');",
"assert(typeof(convertToInteger(\"56\")) === \"number\", 'message: convertToInteger(\"56\")
should return a number');",
"assert(convertToInteger(\"56\") === 56, 'message: convertToInteger(\"56\")
should return 56');",
- "assert(convertToInteger(\"77\") === 77, 'message: convertToInteger(\"56\")
should return 77');",
- "assert(!isNaN(convertToInteger(\"JamesBond\")); , 'message: convertToInteger(\"JamesBond\")
should return NaN');"
+ "assert(convertToInteger(\"77\") === 77, 'message: convertToInteger(\"77\")
should return 77');",
+ "assert.isNaN(convertToInteger(\"JamesBond\"), 'message: convertToInteger(\"JamesBond\")
should return NaN');"
],
"type": "waypoint",
"challengeType": 1,
@@ -5651,26 +5617,28 @@
},
{
"id": "587d7b7e367417b2b2512b22",
- "title": "Use the parseInt function with a radix",
+ "title": "Use the parseInt Function with a Radix",
"description": [
- "The parseInt() function parses a string and returns an integer. The radix variable defines the number system to convert from.",
+ "The parseInt()
function parses a string and returns an integer. It takes a second argument for the radix, which specifies the base of the number in the string. The radix can be an integer between 2 and 36.",
"The function call looks like:",
- "parseInt(string, radix);",
- "var a = parseInt(\"11\", 2);",
- "Here the radix variable defines that \"11\" is in binary system.",
- "The above function will convert the string \"11\" to an integer 3.",
- "Instructions",
- "Using the parseInt() function, write a function that converts binary numbers to integers and returns them."
+ "parseInt(string, radix);
",
+ "And here's an example:",
+ "var a = parseInt(\"11\", 2);
",
+ "The radix variable says that \"11\" is in the binary system, or base 2. This example converts the string \"11\" to an integer 3.",
+ "parseInt()
in the convertToInteger
function so it converts a binary number to an integer and returns it."
],
"challengeSeed": [
"function convertToInteger(str) {",
- "",
+ " ",
"}",
+ "",
"convertToInteger(\"10011\");"
],
"tail": [],
"solutions": [],
"tests": [
+ "assert(/parseInt/g.test(code), 'message: convertToInteger
should use the parseInt()
function');",
"assert(typeof(convertToInteger(\"10011\")) === \"number\", 'message: convertToInteger(\"10011\")
should return a number');",
"assert(convertToInteger(\"10011\") === 19, 'message: convertToInteger(\"10011\")
should return 19');",
"assert(convertToInteger(\"111001\") === 57, 'message: convertToInteger(\"111001\")
should return 57');",
@@ -5681,43 +5649,68 @@
"translations": {}
},
{
- "id": "587d7b7e367417b2b2512b21",
- "title": "Use multiple Conditional Ternary Operators",
+ "id": "587d7b7e367417b2b2512b24",
+ "title": "Use the Conditional (Ternary) Operator",
"description": [
- "In the previous challenge, we used a single conditional operator. Now, we will learn how to use multiple conditionals.",
- "For example:",
- "function findGreaterOrEqual(a, b, c) {
",
- " if(a === b)
",
- " return \"a and b are equal\";
",
- " else if(a > b)
",
- " return \"a is greater\";
",
- " else
",
- " return \"b is greater\";
",
- "}
",
- "The above function can be written using multiple conditionals like:",
- "function findGreaterOrEqual(a, b) {
",
- " return (a === b) ? \"a and b are equal\" : (a > b) ? \"a is greater\" : \"b is greater\";
",
- "}
",
- "Note that the conditional operator is Right Assosiative.",
- "Instructions",
- "Using a Conditional Operator, check if a number is positive, negative or zero."
+ "The conditional operator, also called the ternary operator, can be used as a one line if-else expression.",
+ "The syntax is:",
+ "condition ? statement-if-true : statement-if-false;
",
+ "The following function uses an if-else statement to check a condition:",
+ "function findGreater(a, b) {", + "This can be re-written using the
if(a > b) {
return \"a is greater\";
}
else {
return \"b is greater\";
}
}
conditional operator
:",
+ "function findGreater(a, b) {", + "
return a > b ? \"a is greater\" : \"b is greater\";
}
conditional operator
in the checkEqual
function to check if two numbers are equal or not. The function should return either true or false."
+ ],
+ "challengeSeed": [
+ "function checkEqual(a, b) {",
+ " ",
+ "}",
+ "",
+ "checkEqual(1, 2);"
+ ],
+ "tail": [],
+ "solutions": [],
+ "tests": [
+ "assert(/.+?\\s*?\\?\\s*?.+?\\s*?:\\s*?.+?/gi.test(code), 'message: checkEqual
should use the conditional operator
');",
+ "assert(checkEqual(1, 2) === false, 'message: checkEqual(1, 2)
should return false');",
+ "assert(checkEqual(1, 1) === true, 'message: checkEqual(1, 1)
should return true');",
+ "assert(checkEqual(1, -1) === false, 'message: checkEqual(1, -1)
should return false');"
+ ],
+ "type": "waypoint",
+ "challengeType": 1,
+ "translations": {}
+ },
+ {
+ "id": "587d7b7e367417b2b2512b21",
+ "title": "Use Multiple Conditional (Ternary) Operators",
+ "description": [
+ "In the previous challenge, you used a single conditional operator
. You can also chain them together to check for multiple conditions.",
+ "The following function uses if, else if, and else statements to check multiple conditions:",
+ "function findGreaterOrEqual(a, b) {", + "The above function can be re-written using multiple
if(a === b) {
return \"a and b are equal\";
}
else if(a > b) {
return \"a is greater\";
}
else {
return \"b is greater\";
}
}
conditional operators
:",
+ "function findGreaterOrEqual(a, b) {", + "
return (a === b) ? \"a and b are equal\" : (a > b) ? \"a is greater\" : \"b is greater\";
}
conditional operators
in the checkSign
function to check if a number is positive, negative or zero."
],
"challengeSeed": [
"function checkSign(num) {",
- "",
+ " ",
"}",
+ "",
"checkSign(10);"
],
"tail": [],
"solutions": [],
"tests": [
- "assert(checkSign(10) === 'positive', 'message: checkSign(10)
should return positive');",
- "assert(checkSign(-12) === 'negative', 'message: checkSign(-12)
should return negative');",
- "assert(checkSign(0) === 'zero', 'message: checkSign(0) should return zero');"
+ "assert(/.+?\\s*?\\?\\s*?.+?\\s*?:\\s*?.+?\\s*?\\?\\s*?.+?\\s*?:\\s*?.+?/gi.test(code), 'message: checkSign
should use multiple conditional operators
');",
+ "assert(checkSign(10) === 'positive', 'message: checkSign(10)
should return \"positive\". Note that capitalization matters');",
+ "assert(checkSign(-12) === 'negative', 'message: checkSign(-12)
should return \"negative\". Note that capitalization matters');",
+ "assert(checkSign(0) === 'zero', 'message: checkSign(0)
should return \"zero\". Note that capitalization matters');"
],
"type": "waypoint",
"challengeType": 1,
"translations": {}
}
]
-}
\ No newline at end of file
+}