More bonfire improvements, restoring functionality to original bonfire module after growing it to accept the challenge framework
This commit is contained in:
@ -34,23 +34,8 @@ var nonChallengeValue = '/*Welcome to Bonfire, Free Code Camp\'s future CoderByt
|
||||
' });\n' +
|
||||
'}\n' +
|
||||
'expect(test()).to.be.a("array");\n\n' +
|
||||
'assert.deepEqual(test(), [1,4,9]);';
|
||||
|
||||
// Default seed for editor if one isn't provided
|
||||
var nonChallengeSeed = 'test();';
|
||||
var editorValue;
|
||||
|
||||
|
||||
|
||||
|
||||
if (challengeSeed) {
|
||||
editorValue = challengeSeed + '\n\n' + challengeEntryPoint;
|
||||
} else {
|
||||
editorValue = nonChallengeValue;
|
||||
}
|
||||
|
||||
|
||||
myCodeMirror.setValue(editorValue);
|
||||
'assert.deepEqual(test(), [1,4,9]);\n\n' +
|
||||
'test();';
|
||||
|
||||
var codeOutput = CodeMirror.fromTextArea(document.getElementById("codeOutput"), {
|
||||
lineNumbers: false,
|
||||
@ -68,6 +53,26 @@ var info = editor.getScrollInfo();
|
||||
var after = editor.charCoords({line: editor.getCursor().line + 1, ch: 0}, "local").top;
|
||||
if (info.top + info.clientHeight < after)
|
||||
editor.scrollTo(null, after - info.clientHeight + 3);
|
||||
|
||||
var editorValue;
|
||||
|
||||
|
||||
var challengeSeed = challengeSeed || null;
|
||||
var publicTests = publicTests || [];
|
||||
var privateTests = privateTests || [];
|
||||
var challengeEntryPoint = challengeEntryPoint || null;
|
||||
var challengeEntryPointNegate = challengeEntryPointNegate || null;
|
||||
|
||||
|
||||
if (challengeSeed !== null) {
|
||||
editorValue = challengeSeed + '\n\n' + challengeEntryPoint;
|
||||
} else {
|
||||
editorValue = nonChallengeValue;
|
||||
}
|
||||
|
||||
|
||||
myCodeMirror.setValue(editorValue);
|
||||
|
||||
function doLinting () {
|
||||
editor.operation(function () {
|
||||
for (var i = 0; i < widgets.length; ++i)
|
||||
@ -91,6 +96,28 @@ function doLinting () {
|
||||
});
|
||||
};
|
||||
|
||||
$('#submitButton').on('click', function () {
|
||||
bonfireExecute();
|
||||
});
|
||||
|
||||
function bonfireExecute() {
|
||||
tests = null;
|
||||
$('#codeOutput').empty();
|
||||
var userJavaScript = myCodeMirror.getValue();
|
||||
userJavaScript = removeComments(userJavaScript);
|
||||
userJavaScript = scrapeTests(userJavaScript);
|
||||
submit(userJavaScript, function(cls, message) {
|
||||
if (cls) {
|
||||
codeOutput.setValue(message.error);
|
||||
runTests('Error', null);
|
||||
} else {
|
||||
codeOutput.setValue(message.output);
|
||||
message.input = removeLogs(message.input);
|
||||
runTests(null, message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var replaceQuotesInTests = function() {
|
||||
tests.forEach(function(elt, ix, arr) {
|
||||
arr[ix].text = arr[ix].text.replace(/\"/g,'\'');
|
||||
@ -103,17 +130,6 @@ var testSalt = Math.random();
|
||||
|
||||
var scrapeTests = function(userJavaScript) {
|
||||
|
||||
|
||||
|
||||
var checkIfUserSuppliedEntry = new RegExp(challengeEntryPointNegate, 'g');
|
||||
|
||||
var userEntryCheck = checkIfUserSuppliedEntry.test(userJavaScript);
|
||||
if (!userEntryCheck) {
|
||||
|
||||
userJavaScript += '\n' + challengeEntryPoint;
|
||||
} else {
|
||||
// do nothing?
|
||||
}
|
||||
for (var i = 0; i < publicTests.length; i++) {
|
||||
userJavaScript += '\n' + publicTests[i];
|
||||
}
|
||||
@ -147,32 +163,10 @@ function removeComments(userJavaScript) {
|
||||
}
|
||||
|
||||
function removeLogs(userJavaScript) {
|
||||
//return userJavaScript.replace(/(console\.[\w]+\s*\(.*\;)/g, '');
|
||||
return userJavaScript.replace(/(console\.[\w]+\s*\(.*\;)/g, '');
|
||||
return userJavaScript;
|
||||
}
|
||||
|
||||
$('#submitButton').on('click', function () {
|
||||
bonfireExecute();
|
||||
});
|
||||
|
||||
function bonfireExecute() {
|
||||
tests = null;
|
||||
$('#codeOutput').empty();
|
||||
var userJavaScript = myCodeMirror.getValue();
|
||||
userJavaScript = removeComments(userJavaScript);
|
||||
userJavaScript = scrapeTests(userJavaScript);
|
||||
submit(userJavaScript, function(cls, message) {
|
||||
if (cls) {
|
||||
codeOutput.setValue(message.error);
|
||||
runTests('Error', null);
|
||||
} else {
|
||||
codeOutput.setValue(message.output);
|
||||
message.input = removeLogs(message.input);
|
||||
runTests(null, message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var pushed = false;
|
||||
var createTestDisplay = function() {
|
||||
if (pushed) {
|
||||
|
@ -28,15 +28,8 @@
|
||||
"name": "Validate US Telephone Numbers",
|
||||
"difficulty": 3,
|
||||
"description": [
|
||||
"You are in charge of a campground's website signup form. Specifically, you have been asked to validate US phone numbers before forms are submitted.",
|
||||
"But consider yourself forewarned: the camp leader is quick to anger. So don't try to pull something like forcing the user to enter a phone number in a predefined format. He can't stand it when coders are lazy. Don't be lazy, or he might throw you in the fire pit.",
|
||||
"The user cmay fill out the form field any way they choose as long as it is a valid US number. The following are all valid formats for US numbers:",
|
||||
" 555-555-5555",
|
||||
" (555)555-5555",
|
||||
" (555) 555-5555",
|
||||
" 555 555 5555",
|
||||
" 5555555555",
|
||||
" 1 555 555 5555",
|
||||
"The user may fill out the form field any way they choose as long as it is a valid US number. The following are all valid formats for US numbers:",
|
||||
"555-555-5555, (555)555-5555, (555) 555-5555, 555 555 5555, 5555555555, 1 555 555 5555",
|
||||
"For this challenge you will be presented with a string such as \"800-692-7753\" or \"8oo-six427676;laskdjf\". Your job is to validate or reject the US phone number based on any combination of the formats provided above. The area code is required. If the country code code is provided, you must confirm that the country code is \"1\". Return true if the string is a valid US phone number; otherwise false."
|
||||
],
|
||||
"publicTests": [
|
||||
@ -59,7 +52,7 @@
|
||||
"assert.deepEqual(telephoneCheck(\"2(757)622-7382\"), false);"
|
||||
],
|
||||
"challengeSeed": "function telephoneCheck(str) {\n // Good luck!\n return true;\n}\n\n",
|
||||
"challengeEntryPoint": "telephoneCheck(\"555-555-5555\")",
|
||||
"challengeEntryPoint": "telephoneCheck(\"555-555-5555\");",
|
||||
"bonfireNumber": 2,
|
||||
"challengeEntryPointNegate" : "palindrome\\([^str].*\\;"
|
||||
}
|
||||
|
Reference in New Issue
Block a user