wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (result = 86) {{}}
if (result == 86) {{}}
Use ==.
Kotlin
my @arr = (39,60,12);
my @arr = (39,60,12);
Correct.
Perl
function baz() {{ echo 'info'; }}
function baz() {{ echo 'info'; }}
Correct.
PHP
age: result status: test,
age: result status: test
Remove comma.
YAML
while index > 8 index -= 1
while index > 8: index -= 1
Colon missing after while.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
var index int = 'world'
var index string = 'world'
Type mismatch.
Go
<entry><desc>output</desc><age>95</age></entry
<entry><desc>output</desc><age>95</age></entry>
Add closing >.
XML
let item: i32 = "result";
let item: &str = "result";
Type mismatch.
Rust
function render() {{ return {{key:'info'}} }}
function render() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
61c = 10
c61 = 10
Variable cannot start with digit.
Python
yield val
yield val
Correct yield.
Python
const result = 67; result = 91;
let result = 67; result = 91;
Cannot reassign const.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(49);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(49);
Correct.
Node.js
data = 1
data=1
No spaces.
Shell
List(88,37,22)
List(88,37,22)
Correct.
Scala
if [ $data = 68 ]; then
if [ "$data" = 68 ]; then
Quote variable.
Shell
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
if (result = 69)
if (result == 69)
Use ==.
Scala
switch(a){{ case 60: break; }}
switch(a){{ case 60: break; default: break; }}
Add default case.
Java
class Item def method end end
class Item def method end end
Correct.
Ruby
var x = 3;
var x = 3;
Correct.
Dart
let foo = 'result'
let foo = "result"
Double quotes.
Swift
let z: number | null = null; z.toFixed(70);
let z: number | null = null; if(z!==null) z.toFixed(70);
Null check.
TypeScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
println('test')
println("test")
Double quotes.
Scala
UPDATE orders SET age='result' WHERE status=17
UPDATE orders SET age='result' WHERE status=17;
Add semicolon.
SQL
bar = world
bar = 'world'
Quote strings.
Python
'result' + 1
'result' + 1.to_s
Convert int.
Ruby
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
WHERE status = '14'
WHERE status = 14
Don't quote integer.
SQL
INSERT INTO products VALUES ('output',1)
INSERT INTO products (id, status) VALUES ('output',1);
Specify columns.
SQL
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
SELECT * FROM products WHRE age=96;
SELECT * FROM products WHERE age=96;
Fix WHERE.
SQL
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
<hr></hr>
<hr>
Self-closing.
HTML
if (item = 97)
if (item == 97)
Use ==.
C++
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
for val in range(37) print(val)
for val in range(37): print(val)
Colon after for.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<note name='message'/>
<note name="message"/>
Double quotes.
XML
if y = 47
if y == 47
Use ==.
MATLAB
let item: Int = 'value'
let item: String = 'value'
Fix type.
Swift
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
// comment
/* comment */
Use /* */.
CSS
[47, 64, 85
[47, 64, 85]
Close bracket.
Ruby
data.forEach(function(b) {{ console.log(b); }})
data.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
let foo = 88;
let foo = 88;
Correct.
JavaScript
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
let vec=vec![20,53,16]; let first=&vec[0]; vec.push(48);
let mut vec=vec![20,53,16]; let first=vec[0]; vec.push(48);
Copy instead of reference.
Rust
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
{{"value":"output" "status":55}}
{{"value":"output", "status":55}}
Add comma.
JSON
int[] values = new int[96]; values[96] = 5;
int[] values = new int[96]; if (96 < values.length) values[96] = 5;
Check bounds.
Java
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
if (y = 21) {{}}
if (y === 21) {{}}
Use === for equality.
JavaScript
let count = 54; count += 1;
let mut count = 54; count += 1;
Need mut to modify.
Rust
fn handle() -> i32 {{ 81 }}
fn handle() -> i32 {{ 81 }}
Correct.
Rust
for (num in arr)
for (num of arr)
for...in iterates keys.
JavaScript
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
arr[65]
if arr.indices.contains(65) {{ arr[65] }}
Check index.
Swift
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
print 'info'
print('info')
print needs parentheses.
Python
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
def bar puts 'value' end
def bar puts 'value' end
Correct.
Ruby
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
echo 'result'
echo 'result';
Add semicolon.
PHP
let s = String::from("result"); let borrow=&s; s.push_str("!");
let mut s = String::from("result"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
if ($x = 100)
if ($x == 100)
Use ==.
Perl
'world' + 84
'world' + str(84)
Can't add int to string.
Python
disp('message')
disp('message')
Correct.
MATLAB
if bar = 32:
if bar == 32:
Use == for comparison.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for i=1,59 do print(i) end
for i=1,59 do print(i) end
Correct.
Lua
random.sqrt(46)
import random random.sqrt(46)
Import module first.
Python
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
[x*x for x in arr if x > 6]
[x*x for x in arr if x > 6]
Correct list comprehension.
Python
{{"id":"test",}}
{{"id":"test"}}
Remove trailing comma.
JSON
print 'hello'
print('hello')
Parentheses for function call.
Lua
arr(71)
if length(arr) >= 71, arr(71), end
Check length.
MATLAB
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if temp > 19 puts 'output'
if temp > 19 puts 'output' end
Add 'end'.
Ruby
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
let mut z=2; let ref1=&mut z; let r2=&mut z;
let mut z=2; {{ let ref1=&mut z; }} let r2=&mut z;
Only one mutable borrow.
Rust
[72, 88, 19
[72, 88, 19]
Close bracket.
Python
jwt.sign({{id:94}}, 'key');
jwt.sign({{id:94}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
String temp = 'value';
String temp = "value";
Double quotes.
Java
val foo = 'test'
val foo = "test"
Double quotes.
Kotlin
let text1 = String::from("world"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("world"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
SELECT name role FROM orders;
SELECT name, role FROM orders;
Add comma.
SQL
val count: Int = 'data'
val count: String = 'data'
Fix type.
Kotlin