Skip to content

Commit 128a7b3

Browse files
Merge pull request #737 from ossf/hello_answer_in_js
Hello answer in js
2 parents 989fe04 + 0539991 commit 128a7b3

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

docs/labs/checker.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,12 +781,15 @@ function setupInfo() {
781781
};
782782
};
783783
if (info.correct != null) {
784-
if (correct.length > 0) {
784+
if (correctRe.length > 0) {
785785
alert("Error: Info defines correct value but it's overridden.");
786786
} else if (!(info.correct instanceof Array)) {
787787
alert('Error: Info correct hints must be array.');
788788
} else {
789-
correct = info.correct.map((s) => trimNewlines(s));
789+
let correct = info.correct.map((s) => trimNewlines(s));
790+
// Set global variable with compiled correct answer
791+
correctRe = correct.map((s) =>
792+
processRegex(s, `correct answer ${s}`, true));
790793
};
791794
};
792795
}

docs/labs/hello.html

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,6 @@
1111
<link rel="license" href="https://creativecommons.org/licenses/by/4.0/">
1212

1313
<!-- See create_labs.md for how to create your own lab! -->
14-
15-
<!-- Sample expected answer -->
16-
<script id="expected0" type="plain/text">
17-
console.log("Hello, world!");
18-
</script>
19-
20-
<!-- Full pattern of correct answer -->
21-
<script id="correct0" type="plain/text">
22-
\s* console \. log \( (["'`])Hello,\x20world!\1 \) ; \s*
23-
</script>
24-
2514
</head>
2615
<body>
2716
<!-- For GitHub Pages formatting: -->

docs/labs/hello.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ info =
6565
examples: [ [ " console.log(\"Hello, world!\") " ] ]
6666
}
6767
],
68+
expected: ['console.log("Hello, world!");'],
69+
correct:
70+
[String.raw`\s* console \. log \(
71+
(["'${BACKQUOTE}])Hello,\x20world!\1 \) ; \s*`],
6872
successes: [
6973
[ " console . log( \"Hello, world!\" ) ; " ],
7074
[ " console . log( 'Hello, world!' ) ; " ],

0 commit comments

Comments
 (0)