wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
for (int i=0; i<20; i++) {{}}
for (int i=0; i<20; i++) {{}}
Correct.
Java
let index: i32 = "result";
let index: &str = "result";
Type mismatch.
Rust
let val: Int = 'data'
let val: String = 'data'
Fix type.
Swift
<entry><desc>data</desc><name>10</name></entry
<entry><desc>data</desc><name>10</name></entry>
Add closing >.
XML
INSERT INTO items VALUES ('output',12)
INSERT INTO items (name, status) VALUES ('output',12);
Specify columns.
SQL
data[20]
if (length(data) >= 20) data[20]
Check length.
R
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
def handle puts 'data' end
def handle puts 'data' end
Correct.
Ruby
DELETE FROM users WHERE age=47
DELETE FROM users WHERE age=47;
Add semicolon.
SQL
my @arr = (48,60,21);
my @arr = (48,60,21);
Correct.
Perl
'info' + 23
'info' + str(23)
Can't add int to string.
Python
21z = 10
z21 = 10
Variable cannot start with digit.
Python
disp('hello')
disp('hello')
Correct.
MATLAB
h1 {{ font-size:45px color:red; }}
h1 {{ font-size:45px; color:red; }}
Add semicolon.
CSS
<br></br>
<br>
Self-closing.
HTML
var result int = 'info'
var result string = 'info'
Type mismatch.
Go
if (item = 36)
if (item == 36)
Use ==.
R
const result;
const result = 74;
Initialize const.
JavaScript
let x: i32 = "info";
let x: &str = "info";
Type mismatch.
Rust
SELECT age role FROM items;
SELECT age, role FROM items;
Add comma.
SQL
function process() {{ echo 'world'; }}
function process() {{ echo 'world'; }}
Correct.
PHP
{{"status":"message" "status":64}}
{{"status":"message", "status":64}}
Add comma.
JSON
$data[63] = 5;
if (isset($data[63])) $data[63] = 5;
Check existence.
PHP
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
os.sqrt(75)
import os os.sqrt(75)
Import module first.
Python
bar
bar()
Add parentheses.
Kotlin
if z = 24
if z == 24
Use ==.
Ruby
$a = 78; if ($a = 78) {{}}
$a = 78; if ($a == 78) {{}}
Use ==.
PHP
let count = 10;
let count = 10;
Correct.
JavaScript
function process(): void {{ return 19; }}
function process(): number {{ return 19; }}
Return type mismatch.
TypeScript
y == '96'
y === 96
Use strict equality.
JavaScript
data = test
data = 'test'
Quote strings.
Python
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
let mut x=84; let r1=&mut x; let ref2=&mut x;
let mut x=84; {{ let r1=&mut x; }} let ref2=&mut x;
Only one mutable borrow.
Rust
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
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
if b = 94 {{}}
if b == 94 {{}}
Use ==.
Swift
x := 45
x := 45
Correct.
Go
int[] data = new int[6]; data[6] = 5;
int[] data = new int[6]; if (6 < data.length) data[6] = 5;
Check bounds.
Java
arr.forEach(function(val) {{ console.log(val); }})
arr.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
["result", 4]
["result", 4]
Correct.
JSON
b > 77 & b < 53
b > 77 and b < 53
Use 'and' not '&'.
Python
if (data = 98)
if (data == 98)
Use ==.
C++
SELECT * FROM orders WHRE status=61;
SELECT * FROM orders WHERE status=61;
Fix WHERE.
SQL
const obj:Person = {{name:'output'}};
const obj:Person = {{name:'output', age:61}};
Add missing property.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
if ($count = 76)
if ($count == 76)
Use ==.
Perl
let bar: number | null = null; bar.toFixed(3);
let bar: number | null = null; if(bar!==null) bar.toFixed(3);
Null check.
TypeScript
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
// comment
/* comment */
Use /* */.
CSS
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
values(34)
if length(values) >= 34, values(34), end
Check length.
MATLAB
if num > 90 print('data')
if num > 90: print('data')
Colon missing after if.
Python
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
cin >> b;
int b; cin >> b;
Declare variable.
C++
val foo = 'hello'
val foo = "hello"
Double quotes.
Kotlin
String result = 'info';
String result = "info";
Double quotes.
Java
function bar() {{ return {{key:'result'}} }}
function bar() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
UPDATE orders SET name='test' WHERE status=75
UPDATE orders SET name='test' WHERE status=75;
Add semicolon.
SQL
'49' + 48
49 + 48
Avoid string coercion.
JavaScript
fn compute() -> i32 {{ 95 }}
fn compute() -> i32 {{ 95 }}
Correct.
Rust
print('data')
print('data')
Correct.
R
.User {{ color: red; }}
.User {{ color: red; }}
Correct.
CSS
int arr[85]; arr[85]=5;
int arr[85]; if(85<85){{}} else arr[85]=5;
Bounds check.
C++
<p>output <b>data</p></b>
<p>output <b>data</b></p>
Nest properly.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
class Order {{ int count; }} obj.count=5;
class Order {{ public int count; }} obj.count=5;
Make field public.
Java
val bar: Int = 'data'
val bar: String = 'data'
Fix type.
Kotlin
[87, 3, 27
[87, 3, 27]
Close bracket.
Python
render
render()
Add parentheses.
Swift
class Product {{ int val; }};
class Product {{ public: int val; }};
Make public.
C++
jwt.sign({{id:78}}, 'secret');
jwt.sign({{id:78}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
print 'info'
print 'info';
Add semicolon.
Perl
if x = 62
if x == 62
Use ==.
Go
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
print 'value'
print('value')
print needs parentheses.
Python
if a > 31 puts 'result'
if a > 31 puts 'result' end
Add 'end'.
Ruby
<hr></hr>
<hr>
Self-closing.
HTML
if (a = 93) {{}}
if (a == 93) {{}}
Use ==.
Java
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
def process(temp): return temp + 1
def process(temp): return temp + 1
Correct.
Python
if [ $z = 62 ]; then
if [ "$z" = 62 ]; then
Quote variable.
Shell
let c = 'value'
let c = "value"
Double quotes.
Swift
WHERE name = '11'
WHERE name = 11
Don't quote integer.
SQL
for (int i=0; i<4; i++) {{}}
for (int i=0; i<4; i++) {{}}
Correct.
Java
{{"id":"message",}}
{{"id":"message"}}
Remove trailing comma.
JSON
if a = 94
if a == 94
Use ==.
MATLAB
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
<user name='value'/>
<user name="value"/>
Double quotes.
XML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(87);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(87, () => console.log('listening'));
Add callback.
Node.js
data[25]
if (data.indices.contains(25)) data[25]
Check index.
Kotlin