Skip to content

Commit 58c6a5a

Browse files
committed
Started converting first challenge over to json format
1 parent 67e8460 commit 58c6a5a

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

courses/intro/1_string.json

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
tests = `
2+
var assert = require('chai').assert,
3+
Sandbox = require('javascript-sandbox'),
4+
CS = require('./cs.js'),
5+
consoleInput = code[0].code,
6+
userName;
7+
if(typeof(sandbox) == 'undefined') {
8+
var sandbox = new Sandbox();
9+
}
10+
describe('set_name', function() {
11+
it('f_no_name', function() {
12+
var nameUsed;
13+
CS.traverse(consoleInput, function(node) {
14+
if (node.type == "Program" && node.body[0].type == "ExpressionStatement") {
15+
nameUsed = typeof eval(node.body[0].expression.raw) == "string";
16+
}
17+
});
18+
if(nameUsed) {
19+
userName = sandbox.evaluate(consoleInput)
20+
}
21+
assert(nameUsed);
22+
});
23+
it('f_empty_string', function() {
24+
var isNotEmptyString;
25+
CS.traverse(consoleInput, function(node) {
26+
if (node.type == "Program" && node.body[0].type == "ExpressionStatement") {
27+
isNotEmptyString = eval(node.body[0].expression.raw) != "";
28+
}
29+
});
30+
assert(isNotEmptyString);
31+
});
32+
});
33+
details("output", function() {
34+
var message;
35+
try {
36+
message = sandbox.evaluate(consoleInput)
37+
} catch(e) {
38+
message = e.message
39+
}
40+
return {
41+
result: message,
42+
clientStore: {
43+
userName: userName
44+
}
45+
};
46+
});
47+
`
48+
49+
failures = {
50+
"f_no_name": {
51+
"message": "Uh oh, it looks like you didn\'t create a string with your first name!",
52+
"hint": "Here's an example that you can type in: `\"Gregg\";`"
53+
},
54+
"f_empty_string": {
55+
"message": "You have the quotes, but you need to put your name inside them."
56+
"hint": "Here's an example that you can type in: `\"Gregg\";`"
57+
}
58+
}
59+
60+
module.exports = {
61+
"title": "Strings",
62+
"instructions": `Start learning JavaScript with us by typing in your *first name* surrounded by
63+
quotation marks, and ending with a semicolon. For example, I would type my name like this:
64+
\`"Gregg";\``,
65+
"hints": [
66+
"Type in your first name surrounded by double quotes!"
67+
],
68+
"tests": tests,
69+
"failures": failures,
70+
"answer": "Gregg"
71+
}

0 commit comments

Comments
 (0)