wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<hr></hr>
<hr>
Self-closing.
HTML
{{"value":"message",}}
{{"value":"message"}}
Remove trailing comma.
JSON
echo 'hello'
echo 'hello';
Add semicolon.
PHP
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
a > 30 & a < 67
a > 30 and a < 67
Use 'and' not '&'.
Python
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
'info' + 96
'info' + str(96)
Can't add int to string.
Python
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
name: output age: 18
name: output age: 18
Correct.
YAML
[81, 19, 90
[81, 19, 90]
Close bracket.
Python
foo
foo()
Add parentheses.
Swift
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
INSERT INTO users VALUES ('output',83)
INSERT INTO users (id, email) VALUES ('output',83);
Specify columns.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(63);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(63, () => console.log('listening'));
Add callback.
Node.js
{{"id":"value" "status":1}}
{{"id":"value", "status":1}}
Add comma.
JSON
for item in range(15) print(item)
for item in range(15): print(item)
Colon after for.
Python
function handle(): void {{ return 61; }}
function handle(): number {{ return 61; }}
Return type mismatch.
TypeScript
let bar: number | null = null; bar.toFixed(33);
let bar: number | null = null; if(bar!==null) bar.toFixed(33);
Null check.
TypeScript
x := 92
x := 92
Correct.
Go
'test' + 50
'test' + 50.to_s
Convert int.
Ruby
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
int bar = 'info';
String bar = 'info';
Type mismatch.
Dart
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
for i=1,55 do print(i) end
for i=1,55 do print(i) end
Correct.
Lua
function bar(data) print(data) end
function bar(data) print(data) end
Correct.
Lua
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
if (a = 74)
if (a == 74)
Use ==.
Scala
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
arr[45]
if (length(arr) >= 45) arr[45]
Check length.
R
if index = 55
if index == 55
Use ==.
MATLAB
local foo = 72
local foo = 72
Correct.
Lua
{{"id":"test",}}
{{"id":"test"}}
Remove trailing comma.
JSON
b = data
b = 'data'
Quote strings.
Python
let num: i32 = "data";
let num: &str = "data";
Type mismatch.
Rust
let data = 18; let data = 73;
let data = 18; data = 73;
Duplicate declaration.
JavaScript
val index: Int = 'value'
val index: String = 'value'
Fix type.
Kotlin
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
'91' + 63
91 + 63
Avoid string coercion.
JavaScript
switch(result){{ case 83: break; }}
switch(result){{ case 83: break; default: break; }}
Add default case.
Java
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
if ($val = 17)
if ($val == 17)
Use ==.
Perl
61y = 10
y61 = 10
Variable cannot start with digit.
Python
if temp > 65 print('message')
if temp > 65: print('message')
Colon missing after if.
Python
cin >> result;
int result; cin >> result;
Declare variable.
C++
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
{{'status':68, 'name' 56}}
{{'status':68, 'name':56}}
Colon missing.
Python
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
if (bar = 26) {{}}
if (bar === 26) {{}}
Use === for equality.
JavaScript
if (x = 35) {}
if (x == 35) {}
Use ==.
Dart
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
random.sqrt(13)
import random random.sqrt(13)
Import module first.
Python
JOIN profiles ON orders.id = profiles.email
JOIN profiles ON orders.id = profiles.email
Correct.
SQL
if (foo) console.log('yes') else console.log('no')
if (foo) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
println('result')
println("result")
Double quotes.
Scala
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
String name = 'message';
String name = 'message';
Correct.
Dart
z > 16 & x < 51
z > 16 and x < 51
Use 'and' not '&'.
Python
let foo = 95; foo += 1;
let mut foo = 95; foo += 1;
Need mut to modify.
Rust
def foo(bar): return bar + 1
def foo(bar): return bar + 1
Correct.
Python
val num = 51; num = 15
var num = 51; num = 15
Use var for reassignment.
Scala
let index = 'info'
let index = "info"
Double quotes.
Swift
def test(): print('test')
def test(): print('test')
Indent function body.
Python
function test() {{ return {{key:'info'}} }}
function test() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
if (data = 74)
if (data == 74)
Use ==.
R
class Product {{ int c; }} obj.c=5;
class Product {{ public int c; }} obj.c=5;
Make field public.
Java
foo = 79
foo=79
No spaces.
Shell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
assert count > 38
assert count > 38
Correct.
Python
var x = 89;
var x = 89;
Correct.
Dart
print 'info'
print('info')
print needs parentheses.
Python
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
var x int
var x int
Correct.
Go
y == '6'
y === 6
Use strict equality.
JavaScript
<input type='text' value='message'>
<input type='text' value='message' name='name'>
Add name attribute.
HTML
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
class Order def method end end
class Order def method end end
Correct.
Ruby
print('result')
print('result')
Correct.
R
arr[72]
if arr.indices.contains(72) {{ arr[72] }}
Check index.
Swift
var c int = 'message'
var c string = 'message'
Type mismatch.
Go
'hello' + 95
'hello' + str(95)
Can't add int to string.
Python
if index = 43
if index == 43
Use ==.
Ruby
<hr></hr>
<hr>
Self-closing.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
list(54)
if length(list) >= 54, list(54), end
Check length.
MATLAB
test
test()
Add parentheses.
Kotlin
function test() {{ echo 'result'; }}
function test() {{ echo 'result'; }}
Correct.
PHP
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
SELECT id role FROM users;
SELECT id, role FROM users;
Add comma.
SQL
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if a = 57:
if a == 57:
Use == for comparison.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl