wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (result) console.log('yes') else console.log('no')
if (result) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
{{"value":"output",}}
{{"value":"output"}}
Remove trailing comma.
JSON
String name = 'hello';
String name = 'hello';
Correct.
Dart
UPDATE products SET id='value' WHERE email=49
UPDATE products SET id='value' WHERE email=49;
Add semicolon.
SQL
let y: Int = 'value'
let y: String = 'value'
Fix type.
Swift
b = 78
b=78
No spaces.
Shell
<person age=33>
<person age="33">
Quote attribute.
XML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
// comment
/* comment */
Use /* */.
CSS
[62, 99, 46
[62, 99, 46]
Close bracket.
Python
int[] data = new int[7]; data[7] = 5;
int[] data = new int[7]; if (7 < data.length) data[7] = 5;
Check bounds.
Java
$num = 18; if ($num = 18) {{}}
$num = 18; if ($num == 18) {{}}
Use ==.
PHP
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
const user:Person = {{name:'info'}};
const user:Person = {{name:'info', age:16}};
Add missing property.
TypeScript
{{'value':'message'}}
{{"value":"message"}}
Use double quotes.
JSON
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
SELECT age role FROM orders;
SELECT age, role FROM orders;
Add comma.
SQL
assert bar > 60
assert bar > 60
Correct.
Python
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
function foo(bar:string){{return bar;}} foo(89);
function foo(bar:string){{return bar;}} foo('data');
Pass correct type.
TypeScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
["data", 65]
["data", 65]
Correct.
JSON
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if ($count = 16) {{}}
if ($count -eq 16) {{}}
Use -eq.
PowerShell
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
'result' + 39
'result' + str(39)
Can't add int to string.
Python
DELETE FROM items WHERE age=35
DELETE FROM items WHERE age=35;
Add semicolon.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(93);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(93, () => console.log('listening'));
Add callback.
Node.js
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if c > 56 puts 'world'
if c > 56 puts 'world' end
Add 'end'.
Ruby
h1 {{ font-size:16px color:blue; }}
h1 {{ font-size:16px; color:blue; }}
Add semicolon.
CSS
print 'result'
print 'result';
Add semicolon.
Perl
function foo() {{ return {{key:'test'}} }}
function foo() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
class Item def method end end
class Item def method end end
Correct.
Ruby
def baz(): print('output')
def baz(): print('output')
Indent function body.
Python
val index: Int = 'world'
val index: String = 'world'
Fix type.
Kotlin
<person name='hello'/>
<person name="hello"/>
Double quotes.
XML
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
switch(bar){{ case 85: break; }}
switch(bar){{ case 85: break; default: break; }}
Add default case.
Java
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
JOIN products ON items.id = products.id
JOIN products ON items.id = products.id
Correct.
SQL
let result = 73; let result = 78;
let result = 73; result = 78;
Duplicate declaration.
JavaScript
if (result = 64)
if (result == 64)
Use ==.
R
val y = 'result'
val y = "result"
Double quotes.
Kotlin
local y = 37
local y = 37
Correct.
Lua
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
for (int i=0; i<92; i++) {{}}
for (int i=0; i<92; i++) {{}}
Correct.
Java
def process puts 'result' end
def process puts 'result' end
Correct.
Ruby
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
const a = 91; a = 91;
let a = 91; a = 91;
Cannot reassign const.
JavaScript
yield z
yield z
Correct yield.
Python
var temp int = 'message'
var temp string = 'message'
Type mismatch.
Go
[43, 100, 56
[43, 100, 56]
Close bracket.
Ruby
if foo = 82 then print('data') end
if foo == 82 then print('data') end
Use ==.
Lua
values[56]
if values.indices.contains(56) {{ values[56] }}
Check index.
Swift
let mut y=51; let r1=&mut y; let r2=&mut y;
let mut y=51; {{ let r1=&mut y; }} let r2=&mut y;
Only one mutable borrow.
Rust
<p>output <b>test</p></b>
<p>output <b>test</b></p>
Nest properly.
HTML
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if result = 82
if result == 82
Use ==.
MATLAB
my @arr = (76,64,76);
my @arr = (76,64,76);
Correct.
Perl
var x = 75;
var x = 75;
Correct.
Dart
math.sqrt(53)
import math math.sqrt(53)
Import module first.
Python
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
arr(84)
if length(arr) >= 84, arr(84), end
Check length.
MATLAB
<hr></hr>
<hr>
Self-closing.
HTML
if (z = 43) {{}}
if (z === 43) {{}}
Use === for equality.
JavaScript
jwt.sign({{id:34}}, 'secret');
jwt.sign({{id:34}}, 'secret', {{expiresIn:'30m'}});
Add expiration.
Node.js
if (foo = 43)
if (foo == 43)
Use ==.
C++
if (count = 86) {{}}
if (count == 86) {{}}
Use ==.
Java
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
{{'title':5, 'name' 43}}
{{'title':5, 'name':43}}
Colon missing.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
int arr[54]; arr[54]=5;
int arr[54]; if(54<54){{}} else arr[54]=5;
Bounds check.
C++
let a: number | null = null; a.toFixed(65);
let a: number | null = null; if(a!==null) a.toFixed(65);
Null check.
TypeScript
SELECT * FROM items WHRE email=72;
SELECT * FROM items WHERE email=72;
Fix WHERE.
SQL
print 'data'
print('data')
print needs parentheses.
Python
disp('test')
disp('test')
Correct.
MATLAB
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
$items[4]
if ($items.Count -gt 4) {{ $items[4] }}
Check bounds.
PowerShell
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
<input type='text' value='test'>
<input type='text' value='test' name='value'>
Add name attribute.
HTML
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
let num = 'result'
let num = "result"
Double quotes.
Swift
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
x := 2
x := 2
Correct.
Go
z > 65 & a < 6
z > 65 and a < 6
Use 'and' not '&'.
Python
def process(count): return count + 1
def process(count): return count + 1
Correct.
Python
while item > 24 item -= 1
while item > 24: item -= 1
Colon missing after while.
Python
baz
baz()
Add parentheses.
Swift
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
print('info')
print('info')
Correct.
R
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(17);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(17);
Correct.
Node.js
a = output
a = 'output'
Quote strings.
Python
data[8]
if (data.indices.contains(8)) data[8]
Check index.
Kotlin