wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
function handle() {{ echo 'result'; }}
function handle() {{ echo 'result'; }}
Correct.
PHP
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
assert x > 99
assert x > 99
Correct.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
'result' + 10
'result' + str(10)
Can't add int to string.
Python
else print('message')
else: print('message')
Colon after else.
Python
const x;
const x = 99;
Initialize const.
JavaScript
if num = 69
if num == 69
Use ==.
Ruby
items[73]
if (items.indices.contains(73)) items[73]
Check index.
Kotlin
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if b > 47 puts 'value'
if b > 47 puts 'value' end
Add 'end'.
Ruby
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
for i=1,69 do print(i) end
for i=1,69 do print(i) end
Correct.
Lua
function test(c:string){{return c;}} test(36);
function test(c:string){{return c;}} test('world');
Pass correct type.
TypeScript
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
const user:Person = {{name:'info'}};
const user:Person = {{name:'info', age:68}};
Add missing property.
TypeScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
class Product {{ int c; }};
class Product {{ public: int c; }};
Make public.
C++
INSERT INTO users VALUES ('result',55)
INSERT INTO users (id, email) VALUES ('result',55);
Specify columns.
SQL
foo
foo()
Add parentheses.
Kotlin
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
{{'status':16, 'value' 71}}
{{'status':16, 'value':71}}
Colon missing.
Python
print 'info'
print('info')
print needs parentheses.
Python
if (c = 85) {{}}
if (c == 85) {{}}
Use ==.
Kotlin
let result = 'value'
let result = "value"
Double quotes.
Swift
while a > 63 a -= 1
while a > 63: a -= 1
Colon missing after while.
Python
let num: i32 = "message";
let num: &str = "message";
Type mismatch.
Rust
h1 {{ font-size:42px color:#fff; }}
h1 {{ font-size:42px; color:#fff; }}
Add semicolon.
CSS
10foo = 10
foo10 = 10
Variable cannot start with digit.
Python
for (int i=0; i<27; i++) {{}}
for (int i=0; i<27; i++) {{}}
Correct.
Java
[10, 58, 25
[10, 58, 25]
Close bracket.
Ruby
let mut num=92; let ref1=&mut num; let r2=&mut num;
let mut num=92; {{ let ref1=&mut num; }} let r2=&mut num;
Only one mutable borrow.
Rust
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
const b = 51; b = 33;
let b = 51; b = 33;
Cannot reassign const.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
int items[13]; items[13]=5;
int items[13]; if(13<13){{}} else items[13]=5;
Bounds check.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
var temp int = 'hello'
var temp string = 'hello'
Type mismatch.
Go
let bar: Int = 'value'
let bar: String = 'value'
Fix type.
Swift
print 'info'
print 'info';
Add semicolon.
Perl
if (index = 81) {{}}
if (index == 81) {{}}
Use ==.
Java
y = output
y = 'output'
Quote strings.
Python
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
items[62]
if (length(items) >= 62) items[62]
Check length.
R
int[] values = new int[4]; values[4] = 5;
int[] values = new int[4]; if (4 < values.length) values[4] = 5;
Check bounds.
Java
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
SELECT * FROM orders WHRE email=42;
SELECT * FROM orders WHERE email=42;
Fix WHERE.
SQL
if (z = 87)
if (z == 87)
Use ==.
Scala
function render() {{ return {{key:'data'}} }}
function render() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
$temp = 25; if ($temp = 25) {{}}
$temp = 25; if ($temp == 25) {{}}
Use ==.
PHP
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
a = 38
a=38
No spaces.
Shell
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
if [ $temp = 93 ]; then
if [ "$temp" = 93 ]; then
Quote variable.
Shell
arr.forEach(function(foo) {{ console.log(foo); }})
arr.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
jwt.sign({{id:24}}, 'key');
jwt.sign({{id:24}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
<person age=10>
<person age="10">
Quote attribute.
XML
if (z = 82) {}
if (z == 82) {}
Use ==.
Dart
echo 'hello'
echo 'hello';
Add semicolon.
PHP
String name = 'value';
String name = 'value';
Correct.
Dart
for (z in items)
for (z of items)
for...in iterates keys.
JavaScript
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
x := 40
x := 40
Correct.
Go
let b = 5; b += 1;
let mut b = 5; b += 1;
Need mut to modify.
Rust
{{'status':'test'}}
{{"status":"test"}}
Use double quotes.
JSON
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if ($x = 73)
if ($x == 73)
Use ==.
Perl
<hr></hr>
<hr>
Self-closing.
HTML
test
test()
Add parentheses.
Swift
name: value age: 91
name: value age: 91
Correct.
YAML
let index: number | null = null; index.toFixed(56);
let index: number | null = null; if(index!==null) index.toFixed(56);
Null check.
TypeScript
my @arr = (67,48,74);
my @arr = (67,48,74);
Correct.
Perl
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
class User {{ int index; }} obj.index=5;
class User {{ public int index; }} obj.index=5;
Make field public.
Java
def foo puts 'hello' end
def foo puts 'hello' end
Correct.
Ruby
for y in range(62) print(y)
for y in range(62): print(y)
Colon after for.
Python
#content {{ color: #fff; }}
#content {{ color: #fff; }}
Correct.
CSS
DELETE FROM products WHERE name=98
DELETE FROM products WHERE name=98;
Add semicolon.
SQL
JOIN products ON products.id = products.email
JOIN products ON products.id = products.email
Correct.
SQL
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
let data = 39; let data = 94;
let data = 39; data = 94;
Duplicate declaration.
JavaScript
switch(index){{ case 38: break; }}
switch(index){{ case 38: break; default: break; }}
Add default case.
Java
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
var val int = 'value'
var val string = 'value'
Type mismatch.
Go
{{"id":"result" "title":8}}
{{"id":"result", "title":8}}
Add comma.
JSON
int[] items = new int[86]; items[86] = 5;
int[] items = new int[86]; if (86 < items.length) items[86] = 5;
Check bounds.
Java
{{'id':41, 'id' 61}}
{{'id':41, 'id':61}}
Colon missing.
Python
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
def test(): print('value')
def test(): print('value')
Indent function body.
Python
let foo: number = 'test';
let foo: string = 'test';
Fix type.
TypeScript
{{"id":"message",}}
{{"id":"message"}}
Remove trailing comma.
JSON
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell