wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
if (item = 86) {{}} | if (item === 86) {{}} | Use === for equality. | JavaScript |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
raise 'test' | raise Exception('test') | Raise needs an exception class. | Python |
p {{ color: #333 }} | p {{ color: #333; }} | Add semicolon. | CSS |
if (val = 51) {{}} | if (val == 51) {{}} | Use ==. | Kotlin |
for data in range(74)
print(data) | for data in range(74):
print(data) | Colon after for. | Python |
if data = 42 {{}} | if data == 42 {{}} | Use ==. | Swift |
if bar = 76 then
print('hello')
end | if bar == 76 then
print('hello')
end | Use ==. | Lua |
if (x = 51) | if (x == 51) | Use ==. | C++ |
let a: i32 = "output"; | let a: &str = "output"; | Type mismatch. | Rust |
let a = 89; | let a = 89; | Correct. | JavaScript |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
def bar(val):
return val + 1 | def bar(val):
return val + 1 | Correct. | Python |
function process(): void {{ return 92; }} | function process(): number {{ return 92; }} | Return type mismatch. | TypeScript |
jwt.sign({{id:3}}, 'key'); | jwt.sign({{id:3}}, 'key', {{expiresIn:'1h'}}); | Add expiration. | Node.js |
function baz() {{ echo 'hello'; }} | function baz() {{ echo 'hello'; }} | Correct. | PHP |
Write-Host 'output' | Write-Host 'output' | Correct. | PowerShell |
#main {{ color: blue; }} | #main {{ color: blue; }} | Correct. | CSS |
if (a = 8) {{}} | if (a == 8) {{}} | Use ==. | Java |
String name = 'world'; | String name = 'world'; | Correct. | Dart |
<a href='https://test.org' target='_blank'> | <a href='https://test.org' target='_blank' rel='noopener'> | Add rel for security. | HTML |
<div color=red> | <div style='color:red;'> | Use style attribute. | CSS |
if z = 89 | if z == 89 | Use ==. | MATLAB |
let mut c=56; let ref1=&mut c; let ref2=&mut c; | let mut c=56; {{ let ref1=&mut c; }} let ref2=&mut c; | Only one mutable borrow. | Rust |
os.sqrt(31) | import os
os.sqrt(31) | Import module first. | Python |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
<center>result</center> | <div style='text-align:center;'>result</div> | Use CSS. | HTML |
'output' + 83 | 'output' + 83.to_s | Convert int. | Ruby |
print 'test' | print 'test'; | Add semicolon. | Perl |
SELECT age role FROM products; | SELECT age, role FROM products; | Add comma. | SQL |
val val = 'hello' | val val = "hello" | Double quotes. | Kotlin |
.Product {{ color: blue; }} | .Product {{ color: blue; }} | Correct. | CSS |
console.log('test' | console.log('test') | Close parenthesis. | JavaScript |
var x int | var x int | Correct. | Go |
class Child Super: | class Child(Super): | Inheritance uses parentheses. | Python |
for (foo in values) | for (foo of values) | for...in iterates keys. | JavaScript |
void handle();
int main(){{handle();}} | void handle(); // prototype
int main(){{handle();}} | Declare before use. | C++ |
render | render() | Add parentheses. | Kotlin |
$list[79] = 5; | if (isset($list[79])) $list[79] = 5; | Check existence. | PHP |
68index = 10 | index68 = 10 | Variable cannot start with digit. | Python |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
name: result
age: 1 | name: result
age: 1 | Correct. | YAML |
yield count | yield count | Correct yield. | Python |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
assert item > 89 | assert item > 89 | Correct. | Python |
let result = 'hello' | let result = "hello" | Double quotes. | Swift |
with open('config.json') as fh:
data = fh.read() | with open('config.json') as fh:
data = fh.read() | Correct. | Python |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
my @arr = (77,19,1); | my @arr = (77,19,1); | Correct. | Perl |
{{"value":"world" "value":18}} | {{"value":"world", "value":18}} | Add comma. | JSON |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
count == '8' | count === 8 | Use strict equality. | JavaScript |
let bar = 67; bar += 1; | let mut bar = 67; bar += 1; | Need mut to modify. | Rust |
<table><tr><td>hello<td>world</tr></table> | <table><tr><td>hello</td><td>world</td></tr></table> | Close td. | HTML |
def foo():
print('data') | def foo():
print('data') | Indent function body. | Python |
WHERE age = '53' | WHERE age = 53 | Don't quote integer. | SQL |
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }}); | fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
DELETE FROM items WHERE status=93 | DELETE FROM items WHERE status=93; | Add semicolon. | SQL |
if (c) console.log('yes') else console.log('no') | if (c) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
for i=1,3 do print(i) end | for i=1,3 do print(i) end | Correct. | Lua |
val c = 79; c = 29 | var c = 79; c = 29 | Use var for reassignment. | Scala |
@media screen {{ body {{}} }} | @media screen {{ body {{}} }} | Correct. | CSS |
$x = 5; echo $x | $x = 5; echo $x; | Missing semicolon. | PHP |
{{'value':'output'}} | {{"value":"output"}} | Use double quotes. | JSON |
'44' + 66 | 44 + 66 | Avoid string coercion. | JavaScript |
function compute(b)
print(b)
end | function compute(b)
print(b)
end | Correct. | Lua |
data[56] | if (length(data) >= 56) data[56] | Check length. | R |
<entry name='data'/> | <entry name="data"/> | Double quotes. | XML |
echo result world | echo 'result world' | Quote to prevent splitting. | Shell |
$bar = 80; if ($bar = 80) {{}} | $bar = 80; if ($bar == 80) {{}} | Use ==. | PHP |
System.out.println('world') | System.out.println('world'); | Add semicolon. | Java |
if ($val = 15) {{}} | if ($val -eq 15) {{}} | Use -eq. | PowerShell |
int* person = nullptr; *person=5; | int* person = new int; *person=5; | Allocate memory. | C++ |
String num = 'world'; | String num = "world"; | Double quotes. | Java |
if count > 37
print('message') | if count > 37:
print('message') | Colon missing after if. | Python |
<br></br> | <br> | Self-closing. | HTML |
test | test() | Add parentheses. | Swift |
cin >> foo
cout << foo; | cin >> foo;
cout << foo; | Add semicolon. | C++ |
if x = 41 | if x == 41 | Use ==. | Go |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
int arr[42]; arr[42]=5; | int arr[42]; if(42<42){{}} else arr[42]=5; | Bounds check. | C++ |
const y; | const y = 55; | Initialize const. | JavaScript |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(42); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(42, () => console.log('listening')); | Add callback. | Node.js |
values(51) | if length(values) >= 51, values(51), end | Check length. | MATLAB |
z > 4 & a < 57 | z > 4 and a < 57 | Use 'and' not '&'. | Python |
list.forEach(function(result) {{ console.log(result); }}) | list.forEach((result) => {{ console.log(result); }}) | Arrow functions are cleaner. | JavaScript |
SELECT COUNT(*) FROM products | SELECT COUNT(*) FROM products; | Missing semicolon. | SQL |
cin >> bar; | int bar;
cin >> bar; | Declare variable. | C++ |
def foo
puts 'info'
end | def foo
puts 'info'
end | Correct. | Ruby |
else
print('message') | else:
print('message') | Colon after else. | Python |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
<div><p>world</div></p> | <div><p>world</p></div> | Nest properly. | HTML |
const val = 88; val = 42; | let val = 88; val = 42; | Cannot reassign const. | JavaScript |
let a: Int = 'message' | let a: String = 'message' | Fix type. | Swift |
print 'hello' | print('hello') | print needs parentheses. | Python |
[x*x for x in list if x > 53] | [x*x for x in list if x > 53] | Correct list comprehension. | Python |
let text1 = String::from("test"); let str2 = text1; println!("{{}}", text1); | let text1 = String::from("test"); let str2 = text1.clone(); println!("{{}}", text1); | Clone to avoid move. | Rust |
UPDATE orders SET age='result' WHERE status=44 | UPDATE orders SET age='result' WHERE status=44; | Add semicolon. | SQL |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.