|
7 | 7 | <link rel="stylesheet" href="checker.css"> |
8 | 8 | <script src="js-yaml.min.js"></script> |
9 | 9 | <script src="checker.js"></script> |
| 10 | +<script src="assert.js"></script> |
10 | 11 | <link rel="license" href="https://creativecommons.org/licenses/by/4.0/"> |
11 | 12 |
|
12 | 13 | <!-- See create_labs.md for how to create your own lab! --> |
13 | 14 |
|
14 | | -<!-- Sample expected answer --> |
15 | | -<script id="expected0" type="plain/text"> |
16 | | - if (bindingResult.hasErrors()) { |
17 | | - return "form"; |
18 | | - } |
19 | | -</script> |
20 | | - |
21 | | -<!-- Full pattern of correct answer --> |
22 | | -<script id="correct0" type="plain/text"> |
23 | | -\s* if \( bindingResult \. hasErrors \( \) \) \{ |
24 | | - return "form" ; |
25 | | - \} \s* |
26 | | -</script> |
27 | | - |
28 | | -<script id="info" type="application/yaml"> |
29 | | ---- |
30 | | -hints: |
31 | | -- present: | |
32 | | - assert |
33 | | - text: The whole point of this exercise is to NOT use `assert` |
34 | | - as a way to validate input from untrusted users. |
35 | | - examples: |
36 | | - - - | |
37 | | - assert !bindingResult.hasErrors(); |
38 | | -- absent: | |
39 | | - ^\s*if |
40 | | - text: Begin with `if` so you can return a result if there are errors. |
41 | | - examples: |
42 | | - - - | |
43 | | - return "form"; |
44 | | -- present: (bindingresult|BindingResult) |
45 | | - text: Java is case-sensitive. Use `bindingResult`, not |
46 | | - `bindingresult` nor `BindingResult`. |
47 | | -- present: (haserrors|HasErrors) |
48 | | - text: Java is case-sensitive. Use `hasErrors`, not |
49 | | - `haserrors` nor `HasErrors`. |
50 | | -# https://docs.oracle.com/javase/specs/jls/se23/html/jls-14.html#jls-14.9 |
51 | | -- present: | |
52 | | - ^\s*if\s*[^\(\s] |
53 | | - text: In Java, after the keyword `if` you must have an open left parenthesis. |
54 | | - Conventionally there is one space between the `if` keyword and the |
55 | | - open left parenthesis. |
56 | | - examples: |
57 | | - - - | |
58 | | - if bindingResult.hasErrors |
59 | | -- present: | |
60 | | - ^\s*if\s*\(\s*\!binding |
61 | | - text: You have an extraneous `!` (not operator). |
62 | | - Use the expression if (bindingResult.hasErrors()) ... |
63 | | - examples: |
64 | | - - - | |
65 | | - if (!bindingResult.hasErrors()) |
66 | | -- absent: | |
67 | | - ^ if \( bindingResult \. hasErrors \( \) \) |
68 | | - text: Begin the answer with the text |
69 | | - `if (bindingResult.hasErrors())` so that a statement will |
70 | | - be executed if that condition is true. |
71 | | -- present: | |
72 | | - if \( bindingResult \. hasErrors \( \) \) [^\{\s] |
73 | | - text: Follow the conditional with an open brace, e.g., |
74 | | - `if (bindingResult.hasErrors()) {...`. |
75 | | -- absent: | |
76 | | - return "form" |
77 | | - text: You need to use `return "form";` somewhere. |
78 | | -- present: | |
79 | | - return "form" |
80 | | - absent: |
81 | | - return "form" ; |
82 | | - text: You need to use `;` (semicolon) after `return "form"` because |
83 | | - in Java statements must be followed by a semicolon. |
84 | | -- absent: | |
85 | | - \} $ |
86 | | - text: The answer needs to end with `}` (closing brace). |
87 | | -successes: |
88 | | - - - | |
89 | | - if ( bindingResult.hasErrors() ) { |
90 | | - return "form"; |
91 | | - } |
92 | | - - | |
93 | | - if ( bindingResult . hasErrors ( ) ) { return "form" ; } |
94 | | -failures: |
95 | | - - | |
96 | | - if ( bindingResult . hasErrors ( ) ) { return "form" } |
97 | | - - | |
98 | | - if ( ! bindingResult . hasErrors ( ) ) { return "form" ; } |
99 | | - - | |
100 | | - if bindingResult . hasErrors ( ) { return "form" ; } |
101 | | - - | |
102 | | - if ( bindingResult . hasErrors ) { return "form" ; } |
103 | | -# debug: true |
104 | | -</script> |
105 | 15 | </head> |
106 | 16 | <body> |
107 | 17 | <!-- For GitHub Pages formatting: --> |
|
0 commit comments