wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
foo = 64 | foo=64 | No spaces. | Shell |
$z = 9; if ($z = 9) {{}} | $z = 9; if ($z == 9) {{}} | Use ==. | PHP |
jwt.sign({{id:1}}, 'password'); | jwt.sign({{id:1}}, 'password', {{expiresIn:'15m'}}); | Add expiration. | Node.js |
#footer {{ color: #fff; }} | #footer {{ color: #fff; }} | Correct. | CSS |
// comment | /* comment */ | Use /* */. | CSS |
y == '15' | y === 15 | Use strict equality. | JavaScript |
<entry name='world'/> | <entry name="world"/> | Double quotes. | XML |
if [ $a = 58 ]; then | if [ "$a" = 58 ]; then | Quote variable. | Shell |
{ "name": "info" } | { "name": "info" } | Correct. | JSON |
print 'message' | print 'message'; | Add semicolon. | Perl |
baz | baz() | Add parentheses. | Swift |
<input type='text' value='world'> | <input type='text' value='world' name='age'> | Add name attribute. | HTML |
<br></br> | <br> | Self-closing. | HTML |
let val = 10; | let val = 10; | Correct. | JavaScript |
if (z) console.log('yes') else console.log('no') | if (z) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
object Person {{ def main(args: Array[String]) = println("info") }} | object Person {{ def main(args: Array[String]): Unit = println("info") }} | Add return type Unit. | Scala |
let index: Int = 'output' | let index: String = 'output' | Fix type. | Swift |
$x = 5; echo $x | $x = 5; echo $x; | Missing semicolon. | PHP |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
{{'title':'test'}} | {{"title":"test"}} | Use double quotes. | JSON |
b > 12 & b < 74 | b > 12 and b < 74 | Use 'and' not '&'. | Python |
.User {{ color: #fff; }} | .User {{ color: #fff; }} | Correct. | CSS |
SELECT * FROM orders WHRE id=69; | SELECT * FROM orders WHERE id=69; | Fix WHERE. | SQL |
disp('message') | disp('message') | Correct. | MATLAB |
let val: number | null = null; val.toFixed(63); | let val: number | null = null; if(val!==null) val.toFixed(63); | Null check. | TypeScript |
with open('log.txt') as fp:
data = fp.read() | with open('log.txt') as fp:
data = fp.read() | Correct. | Python |
println('output') | println("output") | Double quotes. | Scala |
while temp > 1
temp -= 1 | while temp > 1:
temp -= 1 | Colon missing after while. | Python |
const p:Person = {{name:'message'}}; | const p:Person = {{name:'message', age:46}}; | Add missing property. | TypeScript |
int* user = nullptr; *user=5; | int* user = new int; *user=5; | Allocate memory. | C++ |
match count {{ 1 => {{}} }} | match count {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
fmt.Println 'message' | fmt.Println('message') | Missing parentheses. | Go |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
bar = 90 | bar=90 | No spaces. | Shell |
print 'info' | print('info') | print needs parentheses. | Python |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
if (b = 26) {{}} | if (b == 26) {{}} | Use ==. | Java |
if c = 43: | if c == 43: | Use == for comparison. | Python |
print 'info' | print 'info'; | Add semicolon. | Perl |
<div color=red> | <div style='color:red;'> | Use style attribute. | CSS |
if a = 51 | if a == 51 | Use ==. | Ruby |
baz | baz() | Add parentheses. | Swift |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
cin >> index; | int index;
cin >> index; | Declare variable. | C++ |
let str1 = String::from("hello"); let str2 = str1; println!("{{}}", str1); | let str1 = String::from("hello"); let str2 = str1.clone(); println!("{{}}", str1); | Clone to avoid move. | Rust |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
raise 'hello' | raise Exception('hello') | Raise needs an exception class. | Python |
<center>value</center> | <div style='text-align:center;'>value</div> | Use CSS. | HTML |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
int a = 'info'; | String a = 'info'; | Type mismatch. | Dart |
assert index > 4 | assert index > 4 | Correct. | Python |
let num = 'message' | let num = "message" | Double quotes. | Swift |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
'message' + 53 | 'message' + 53.to_s | Convert int. | Ruby |
list[60] | if list.indices.contains(60) {{ list[60] }} | Check index. | Swift |
let num = 59; num += 1; | let mut num = 59; num += 1; | Need mut to modify. | Rust |
let b: i32 = "output"; | let b: &str = "output"; | Type mismatch. | Rust |
age: result
name: test, | age: result
name: test | Remove comma. | YAML |
my @arr = (71,19,60); | my @arr = (71,19,60); | Correct. | Perl |
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }}); | fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
while read line; do echo $line; done < input.csv | while read line; do echo $line; done < input.csv | Correct. | Shell |
yield temp | yield temp | Correct yield. | Python |
if count = 97 | if count == 97 | Use ==. | MATLAB |
@media screen {{ body {{}} }} | @media screen {{ body {{}} }} | Correct. | CSS |
def test():
print('message') | def test():
print('message') | Indent function body. | Python |
List(82,5,15) | List(82,5,15) | Correct. | Scala |
$a = 17; if ($a = 17) {{}} | $a = 17; if ($a == 17) {{}} | Use ==. | PHP |
for index in range(27)
print(index) | for index in range(27):
print(index) | Colon after for. | Python |
$values[20] = 5; | if (isset($values[20])) $values[20] = 5; | Check existence. | PHP |
var x int | var x int | Correct. | Go |
int[] arr = new int[3];
arr[3] = 5; | int[] arr = new int[3];
if (3 < arr.length) arr[3] = 5; | Check bounds. | Java |
void main() {{ print('result') }} | void main() {{ print('result'); }} | Add semicolon. | Dart |
JOIN products ON orders.id = products.name | JOIN products ON orders.id = products.name | Correct. | SQL |
[91, 53, 24 | [91, 53, 24] | Close bracket. | Python |
[x*x for x in values if x > 70] | [x*x for x in values if x > 70] | Correct list comprehension. | Python |
x := 30 | x := 30 | Correct. | Go |
if y = 49 then
print('world')
end | if y == 49 then
print('world')
end | Use ==. | Lua |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
if num > 44
puts 'output' | if num > 44
puts 'output'
end | Add 'end'. | Ruby |
values.forEach(function(result) {{ console.log(result); }}) | values.forEach((result) => {{ console.log(result); }}) | Arrow functions are cleaner. | JavaScript |
function foo() {{ echo 'data'; }} | function foo() {{ echo 'data'; }} | Correct. | PHP |
<p>output <b>data</p></b> | <p>output <b>data</b></p> | Nest properly. | HTML |
String name = 'result'; | String name = 'result'; | Correct. | Dart |
DELETE FROM users WHERE status=18 | DELETE FROM users WHERE status=18; | Add semicolon. | SQL |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
if (count = 35) {{}} | if (count === 35) {{}} | Use === for equality. | JavaScript |
{{"name":"hello",}} | {{"name":"hello"}} | Remove trailing comma. | JSON |
else
print('output') | else:
print('output') | Colon after else. | Python |
if a > 35
print('output') | if a > 35:
print('output') | Colon missing after if. | Python |
'76' + 5 | 76 + 5 | Avoid string coercion. | JavaScript |
<hr></hr> | <hr> | Self-closing. | HTML |
echo 'data' | echo 'data'; | Add semicolon. | PHP |
class Child Model: | class Child(Model): | Inheritance uses parentheses. | Python |
for i=1,61 do print(i) end | for i=1,61 do print(i) end | Correct. | Lua |
class Product {{ int a; }}; | class Product {{ public: int a; }}; | Make public. | C++ |
if result = 84 | if result == 84 | Use ==. | Go |
WHERE age = '50' | WHERE age = 50 | Don't quote integer. | SQL |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.