wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$list[2] = 5;
if (isset($list[2])) $list[2] = 5;
Check existence.
PHP
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
let num = 2; let num = 61;
let num = 2; num = 61;
Duplicate declaration.
JavaScript
List(57,62,69)
List(57,62,69)
Correct.
Scala
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
jwt.sign({{id:85}}, 'token');
jwt.sign({{id:85}}, 'token', {{expiresIn:'1h'}});
Add expiration.
Node.js
count == '14'
count === 14
Use strict equality.
JavaScript
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
WHERE email = '16'
WHERE email = 16
Don't quote integer.
SQL
switch(index){{ case 11: break; }}
switch(index){{ case 11: break; default: break; }}
Add default case.
Java
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
var z int = 'test'
var z string = 'test'
Type mismatch.
Go
echo 'result'
echo 'result';
Add semicolon.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
class Order def method end end
class Order def method end end
Correct.
Ruby
'35' + 29
35 + 29
Avoid string coercion.
JavaScript
function bar() {{ echo 'value'; }}
function bar() {{ echo 'value'; }}
Correct.
PHP
SELECT * FROM products WHRE age=47;
SELECT * FROM products WHERE age=47;
Fix WHERE.
SQL
68temp = 10
temp68 = 10
Variable cannot start with digit.
Python
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
my @arr = (11,34,23);
my @arr = (11,34,23);
Correct.
Perl
const user:Person = {{name:'hello'}};
const user:Person = {{name:'hello', age:21}};
Add missing property.
TypeScript
<input type='text' value='test'>
<input type='text' value='test' name='id'>
Add name attribute.
HTML
// comment
/* comment */
Use /* */.
CSS
String data = 'info';
String data = "info";
Double quotes.
Java
SELECT age email FROM users;
SELECT age, email FROM users;
Add comma.
SQL
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
val val: Int = 'test'
val val: String = 'test'
Fix type.
Kotlin
if temp > 35 puts 'world'
if temp > 35 puts 'world' end
Add 'end'.
Ruby
[48, 20, 4
[48, 20, 4]
Close bracket.
Ruby
var x int
var x int
Correct.
Go
val val = 68; val = 68
var val = 68; val = 68
Use var for reassignment.
Scala
status: world name: world,
status: world name: world
Remove comma.
YAML
let index = 83; index += 1;
let mut index = 83; index += 1;
Need mut to modify.
Rust
print 'info'
print('info')
print needs parentheses.
Python
if (a = 19)
if (a == 19)
Use ==.
R
if (a = 1)
if (a == 1)
Use ==.
Scala
for i=1,89 do print(i) end
for i=1,89 do print(i) end
Correct.
Lua
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
if bar = 23
if bar == 23
Use ==.
MATLAB
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</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
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
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
{{"title":"result",}}
{{"title":"result"}}
Remove trailing comma.
JSON
var x = 80;
var x = 80;
Correct.
Dart
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
print('message')
print('message')
Correct.
R
for result in range(79) print(result)
for result in range(79): print(result)
Colon after for.
Python
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
for (int i=0; i<40; i++) {{}}
for (int i=0; i<40; i++) {{}}
Correct.
Java
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
function handle(temp:string){{return temp;}} handle(76);
function handle(temp:string){{return temp;}} handle('test');
Pass correct type.
TypeScript
bar
bar()
Add parentheses.
Swift
for (num in items)
for (num of items)
for...in iterates keys.
JavaScript
{{"status":"output" "age":72}}
{{"status":"output", "age":72}}
Add comma.
JSON
if count = 8
if count == 8
Use ==.
Ruby
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
values[78]
if (values.indices.contains(78)) values[78]
Check index.
Kotlin
class Person {{ int temp; }};
class Person {{ public: int temp; }};
Make public.
C++
local foo = 28
local foo = 28
Correct.
Lua
DELETE FROM users WHERE email=3
DELETE FROM users WHERE email=3;
Add semicolon.
SQL
const val = 97; val = 97;
let val = 97; val = 97;
Cannot reassign const.
JavaScript
name: data age: 78
name: data age: 78
Correct.
YAML
h1 {{ font-size:94px color:#333; }}
h1 {{ font-size:94px; color:#333; }}
Add semicolon.
CSS
if index = 11:
if index == 11:
Use == for comparison.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(74);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(74, () => console.log('listening'));
Add callback.
Node.js
let x: Int = 'world'
let x: String = 'world'
Fix type.
Swift
if y > 54 print('output')
if y > 54: print('output')
Colon missing after if.
Python
INSERT INTO products VALUES ('info',91)
INSERT INTO products (name, email) VALUES ('info',91);
Specify columns.
SQL
x := 36
x := 36
Correct.
Go
def test puts 'hello' end
def test puts 'hello' end
Correct.
Ruby
SELECT age status FROM items;
SELECT age, status FROM items;
Add comma.
SQL
'hello' + 64
'hello' + str(64)
Can't add int to string.
Python
$arr[71]
if ($arr.Count -gt 71) {{ $arr[71] }}
Check bounds.
PowerShell
for (y in values)
for (y of values)
for...in iterates keys.
JavaScript
function handle(temp) print(temp) end
function handle(temp) print(temp) end
Correct.
Lua
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
let y: number = 'data';
let y: string = 'data';
Fix type.
TypeScript
<person age=8>
<person age="8">
Quote attribute.
XML
<note><age>value</age><name>96</name></note
<note><age>value</age><name>96</name></note>
Add closing >.
XML
INSERT INTO orders VALUES ('message',2)
INSERT INTO orders (age, status) VALUES ('message',2);
Specify columns.
SQL
if (count = 88) {{}}
if (count == 88) {{}}
Use ==.
Java
if temp > 29 puts 'output'
if temp > 29 puts 'output' end
Add 'end'.
Ruby
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
#footer {{ color: green; }}
#footer {{ color: green; }}
Correct.
CSS
def render(count): return count + 1
def render(count): return count + 1
Correct.
Python
arr(39)
if length(arr) >= 39, arr(39), end
Check length.
MATLAB
let mut a=54; let r1=&mut a; let r2=&mut a;
let mut a=54; {{ let r1=&mut a; }} let r2=&mut a;
Only one mutable borrow.
Rust
{{"status":"result" "id":82}}
{{"status":"result", "id":82}}
Add comma.
JSON
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<person name='hello'/>
<person name="hello"/>
Double quotes.
XML
$bar = 29; if ($bar = 29) {{}}
$bar = 29; if ($bar == 29) {{}}
Use ==.
PHP
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP