wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
val bar = 'world'
val bar = "world"
Double quotes.
Kotlin
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
SELECT age status FROM items;
SELECT age, status FROM items;
Add comma.
SQL
{{"title":"output" "name":10}}
{{"title":"output", "name":10}}
Add comma.
JSON
for i=1,53 do print(i) end
for i=1,53 do print(i) end
Correct.
Lua
var c int = 'data'
var c string = 'data'
Type mismatch.
Go
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
String a = 'info';
String a = "info";
Double quotes.
Java
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
$temp = 70; if ($temp = 70) {{}}
$temp = 70; if ($temp == 70) {{}}
Use ==.
PHP
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
[58, 28, 48
[58, 28, 48]
Close bracket.
Ruby
.User {{ color: #fff; }}
.User {{ color: #fff; }}
Correct.
CSS
const x = 29; x = 100;
let x = 29; x = 100;
Cannot reassign const.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
int item = 'output';
String item = 'output';
Type mismatch.
Dart
INSERT INTO users VALUES ('value',28)
INSERT INTO users (age, email) VALUES ('value',28);
Specify columns.
SQL
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
def handle(): print('data')
def handle(): print('data')
Indent function body.
Python
'output' + 41
'output' + 41.to_s
Convert int.
Ruby
let mut bar=94; let r1=&mut bar; let r2=&mut bar;
let mut bar=94; {{ let r1=&mut bar; }} let r2=&mut bar;
Only one mutable borrow.
Rust
<input type='text' value='output'>
<input type='text' value='output' name='id'>
Add name attribute.
HTML
let val = 9; val += 1;
let mut val = 9; val += 1;
Need mut to modify.
Rust
jwt.sign({{id:20}}, 'password');
jwt.sign({{id:20}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
print('value')
print('value')
Correct.
R
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if (count) console.log('yes') else console.log('no')
if (count) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
class Item {{ int item; }};
class Item {{ public: int item; }};
Make public.
C++
let z = 67; let z = 21;
let z = 67; z = 21;
Duplicate declaration.
JavaScript
else print('output')
else: print('output')
Colon after else.
Python
SELECT * FROM orders WHRE status=86;
SELECT * FROM orders WHERE status=86;
Fix WHERE.
SQL
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
echo 'test'
echo 'test';
Add semicolon.
PHP
{{'status':'message'}}
{{"status":"message"}}
Use double quotes.
JSON
if item > 92 puts 'info'
if item > 92 puts 'info' end
Add 'end'.
Ruby
for (int i=0; i<80; i++) {{}}
for (int i=0; i<80; i++) {{}}
Correct.
Java
cin >> data;
int data; cin >> data;
Declare variable.
C++
arr[30]
if (arr.indices.contains(30)) arr[30]
Check index.
Kotlin
disp('test')
disp('test')
Correct.
MATLAB
fn render() -> i32 {{ 89 }}
fn render() -> i32 {{ 89 }}
Correct.
Rust
<p>result <b>data</p></b>
<p>result <b>data</b></p>
Nest properly.
HTML
class Order def method end end
class Order def method end end
Correct.
Ruby
def process puts 'info' end
def process puts 'info' end
Correct.
Ruby
assert z > 90
assert z > 90
Correct.
Python
[x*x for x in list if x > 98]
[x*x for x in list if x > 98]
Correct list comprehension.
Python
["info", 4]
["info", 4]
Correct.
JSON
<entry name='value'/>
<entry name="value"/>
Double quotes.
XML
if (a = 49)
if (a == 49)
Use ==.
R
x := 77
x := 77
Correct.
Go
<?php // code ?>
<?php // code ?>
Correct.
PHP
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
switch(y){{ case 46: break; }}
switch(y){{ case 46: break; default: break; }}
Add default case.
Java
val index = 90; index = 42
var index = 90; index = 42
Use var for reassignment.
Scala
<hr></hr>
<hr>
Self-closing.
HTML
if item = 14
if item == 14
Use ==.
Ruby
if (foo = 63) {}
if (foo == 63) {}
Use ==.
Dart
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
DELETE FROM products WHERE status=64
DELETE FROM products WHERE status=64;
Add semicolon.
SQL
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
my @arr = (41,52,57);
my @arr = (41,52,57);
Correct.
Perl
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(82);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(82);
Correct.
Node.js
let text = String::from("info"); let borrow=&text; text.push_str("!");
let mut text = String::from("info"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
val foo: Int = 'world'
val foo: String = 'world'
Fix type.
Kotlin
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
{{"title":"output",}}
{{"title":"output"}}
Remove trailing comma.
JSON
function bar() {{ echo 'world'; }}
function bar() {{ echo 'world'; }}
Correct.
PHP
echo message world
echo 'message world'
Quote to prevent splitting.
Shell
if foo = 93
if foo == 93
Use ==.
MATLAB
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
if (z = 7)
if (z == 7)
Use ==.
C++
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
for (a in items)
for (a of items)
for...in iterates keys.
JavaScript
print 'data'
print 'data';
Add semicolon.
Perl
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(46);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(46, () => console.log('listening'));
Add callback.
Node.js
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let foo: number = 'message';
let foo: string = 'message';
Fix type.
TypeScript
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
var x int
var x int
Correct.
Go
$list[31]
if ($list.Count -gt 31) {{ $list[31] }}
Check bounds.
PowerShell
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
test
test()
Add parentheses.
Swift
bar
bar()
Add parentheses.
Kotlin
if val > 93 print('hello')
if val > 93: print('hello')
Colon missing after if.
Python
re.sqrt(66)
import re re.sqrt(66)
Import module first.
Python
int arr[71]; arr[71]=5;
int arr[71]; if(71<71){{}} else arr[71]=5;
Bounds check.
C++
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if b = 29 then print('world') end
if b == 29 then print('world') end
Use ==.
Lua
let vec=vec![3,2,30]; let head=&vec[0]; vec.push(63);
let mut vec=vec![3,2,30]; let head=vec[0]; vec.push(63);
Copy instead of reference.
Rust
while result > 10 result -= 1
while result > 10: result -= 1
Colon missing after while.
Python