wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$items[57] = 5;
if (isset($items[57])) $items[57] = 5;
Check existence.
PHP
66item = 10
item66 = 10
Variable cannot start with digit.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(67);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(67, () => console.log('listening'));
Add callback.
Node.js
if (result = 60) {{}}
if (result === 60) {{}}
Use === for equality.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if x = 69:
if x == 69:
Use == for comparison.
Python
object Item {{ def main(args: Array[String]) = println("hello") }}
object Item {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
int[] data = new int[18]; data[18] = 5;
int[] data = new int[18]; if (18 < data.length) data[18] = 5;
Check bounds.
Java
'output' + 89
'output' + str(89)
Can't add int to string.
Python
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
disp('value')
disp('value')
Correct.
MATLAB
cin >> data;
int data; cin >> data;
Declare variable.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
def render(): print('output')
def render(): print('output')
Indent function body.
Python
if (x = 38)
if (x == 38)
Use ==.
R
items[27]
if (items.indices.contains(27)) items[27]
Check index.
Kotlin
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
$count = 48; if ($count = 48) {{}}
$count = 48; if ($count == 48) {{}}
Use ==.
PHP
if (num = 100)
if (num == 100)
Use ==.
Scala
{{"name":"test" "title":88}}
{{"name":"test", "title":88}}
Add comma.
JSON
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
values(25)
if length(values) >= 25, values(25), end
Check length.
MATLAB
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(1);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(1);
Correct.
Node.js
const foo;
const foo = 3;
Initialize const.
JavaScript
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
[x*x for x in items if x > 2]
[x*x for x in items if x > 2]
Correct list comprehension.
Python
age: test id: test,
age: test id: test
Remove comma.
YAML
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
String name = 'value';
String name = 'value';
Correct.
Dart
data = data
data = 'data'
Quote strings.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
x := 88
x := 88
Correct.
Go
if item = 52
if item == 52
Use ==.
Ruby
data[38]
if (data.indices.contains(38)) data[38]
Check index.
Kotlin
function test() {{ return {{key:'output'}} }}
function test() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
y = 80
y=80
No spaces.
Shell
let mut num=39; let ref1=&mut num; let ref2=&mut num;
let mut num=39; {{ let ref1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
<note name='world'/>
<note name="world"/>
Double quotes.
XML
for i=1,52 do print(i) end
for i=1,52 do print(i) end
Correct.
Lua
{{"age":"data" "title":64}}
{{"age":"data", "title":64}}
Add comma.
JSON
val data = 'message'
val data = "message"
Double quotes.
Kotlin
.Order {{ color: #fff; }}
.Order {{ color: #fff; }}
Correct.
CSS
print('test')
print('test')
Correct.
R
SELECT * FROM users WHRE name=62;
SELECT * FROM users WHERE name=62;
Fix WHERE.
SQL
let result: number | null = null; result.toFixed(26);
let result: number | null = null; if(result!==null) result.toFixed(26);
Null check.
TypeScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
if [ $c = 38 ]; then
if [ "$c" = 38 ]; then
Quote variable.
Shell
disp('world')
disp('world')
Correct.
MATLAB
<hr></hr>
<hr>
Self-closing.
HTML
render
render()
Add parentheses.
Kotlin
const num = 62; num = 86;
let num = 62; num = 86;
Cannot reassign const.
JavaScript
DELETE FROM products WHERE email=8
DELETE FROM products WHERE email=8;
Add semicolon.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let str1 = String::from("result"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("result"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
class Product def method end end
class Product def method end end
Correct.
Ruby
yield index
yield index
Correct yield.
Python
$list[42]
if ($list.Count -gt 42) {{ $list[42] }}
Check bounds.
PowerShell
function bar(): void {{ return 52; }}
function bar(): number {{ return 52; }}
Return type mismatch.
TypeScript
jwt.sign({{id:12}}, 'token');
jwt.sign({{id:12}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
if ($val = 28)
if ($val == 28)
Use ==.
Perl
'result' + 31
'result' + 31.to_s
Convert int.
Ruby
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
def foo puts 'hello' end
def foo puts 'hello' end
Correct.
Ruby
List(8,39,79)
List(8,39,79)
Correct.
Scala
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let x = 'hello'
let x = "hello"
Double quotes.
Swift
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
const user:Person = {{name:'world'}};
const user:Person = {{name:'world', age:95}};
Add missing property.
TypeScript
my @arr = (80,90,13);
my @arr = (80,90,13);
Correct.
Perl
let index: Int = 'info'
let index: String = 'info'
Fix type.
Swift
let count: i32 = "test";
let count: &str = "test";
Type mismatch.
Rust
for a in range(31) print(a)
for a in range(31): print(a)
Colon after for.
Python
<person age=90>
<person age="90">
Quote attribute.
XML
print 'value'
print('value')
print needs parentheses.
Python
cin >> z;
int z; cin >> z;
Declare variable.
C++
name: test title: data,
name: test title: data
Remove comma.
YAML
h1 {{ font-size:83px color:green; }}
h1 {{ font-size:83px; color:green; }}
Add semicolon.
CSS
let bar: number = 'world';
let bar: string = 'world';
Fix type.
TypeScript
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
INSERT INTO products VALUES ('output',96)
INSERT INTO products (age, role) VALUES ('output',96);
Specify columns.
SQL
println('result')
println("result")
Double quotes.
Scala
if (val = 77)
if (val == 77)
Use ==.
R
items[58]
if items.indices.contains(58) {{ items[58] }}
Check index.
Swift
'test' + 54
'test' + str(54)
Can't add int to string.
Python
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
while c > 66 c -= 1
while c > 66: c -= 1
Colon missing after while.
Python
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
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
let c = 100; c += 1;
let mut c = 100; c += 1;
Need mut to modify.
Rust
<p>result <b>hello</p></b>
<p>result <b>hello</b></p>
Nest properly.
HTML