wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
'world' + 37
'world' + 37.to_s
Convert int.
Ruby
[40, 56, 80
[40, 56, 80]
Close bracket.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
switch(index){{ case 28: break; }}
switch(index){{ case 28: break; default: break; }}
Add default case.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
jwt.sign({{id:71}}, 'key');
jwt.sign({{id:71}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
'result' + 96
'result' + 96.to_s
Convert int.
Ruby
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
cin >> item;
int item; cin >> item;
Declare variable.
C++
<hr></hr>
<hr>
Self-closing.
HTML
var x int
var x int
Correct.
Go
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
$index = 61; if ($index = 61) {{}}
$index = 61; if ($index == 61) {{}}
Use ==.
PHP
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
int data[95]; data[95]=5;
int data[95]; if(95<95){{}} else data[95]=5;
Bounds check.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
class Person def method end end
class Person def method end end
Correct.
Ruby
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if ($data = 84)
if ($data == 84)
Use ==.
Perl
disp('message')
disp('message')
Correct.
MATLAB
if (x = 29) {}
if (x == 29) {}
Use ==.
Dart
list(11)
if length(list) >= 11, list(11), end
Check length.
MATLAB
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
for (int i=0; i<44; i++) {{}}
for (int i=0; i<44; i++) {{}}
Correct.
Java
WHERE email = '89'
WHERE email = 89
Don't quote integer.
SQL
if (b) console.log('yes') else console.log('no')
if (b) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let mut temp=81; let r1=&mut temp; let ref2=&mut temp;
let mut temp=81; {{ let r1=&mut temp; }} let ref2=&mut temp;
Only one mutable borrow.
Rust
data.forEach(function(temp) {{ console.log(temp); }})
data.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
if (x = 16) {{}}
if (x == 16) {{}}
Use ==.
Java
{{'age':2, 'title' 100}}
{{'age':2, 'title':100}}
Colon missing.
Python
let temp: number | null = null; temp.toFixed(71);
let temp: number | null = null; if(temp!==null) temp.toFixed(71);
Null check.
TypeScript
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
// comment
/* comment */
Use /* */.
CSS
[x*x for x in data if x > 70]
[x*x for x in data if x > 70]
Correct list comprehension.
Python
<entry name='world'/>
<entry name="world"/>
Double quotes.
XML
[75, 9, 66
[75, 9, 66]
Close bracket.
Ruby
if (foo = 46)
if (foo == 46)
Use ==.
Scala
<entry><age>result</age><desc>73</desc></entry
<entry><age>result</age><desc>73</desc></entry>
Add closing >.
XML
49index = 10
index49 = 10
Variable cannot start with digit.
Python
if ($result = 53) {{}}
if ($result -eq 53) {{}}
Use -eq.
PowerShell
println('output')
println("output")
Double quotes.
Scala
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
function bar() {{ echo 'value'; }}
function bar() {{ echo 'value'; }}
Correct.
PHP
SELECT age email FROM orders;
SELECT age, email FROM orders;
Add comma.
SQL
else print('info')
else: print('info')
Colon after else.
Python
if x = 87:
if x == 87:
Use == for comparison.
Python
let b = 71; let b = 12;
let b = 71; b = 12;
Duplicate declaration.
JavaScript
my @arr = (94,41,58);
my @arr = (94,41,58);
Correct.
Perl
if foo = 29
if foo == 29
Use ==.
Go
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
let item = 12;
let item = 12;
Correct.
JavaScript
const b;
const b = 79;
Initialize const.
JavaScript
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
print 'world'
print 'world';
Add semicolon.
Perl
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let s1 = String::from("message"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
echo 'value'
echo 'value';
Add semicolon.
PHP
echo data data
echo 'data data'
Quote to prevent splitting.
Shell
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
if b = 55
if b == 55
Use ==.
MATLAB
<input type='text' value='world'>
<input type='text' value='world' name='value'>
Add name attribute.
HTML
class Order {{ int result; }};
class Order {{ public: int result; }};
Make public.
C++
y > 24 & z < 51
y > 24 and z < 51
Use 'and' not '&'.
Python
for (c in items)
for (c of items)
for...in iterates keys.
JavaScript
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
result = output
result = 'output'
Quote strings.
Python
var c int = 'value'
var c string = 'value'
Type mismatch.
Go
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
let c: i32 = "result";
let c: &str = "result";
Type mismatch.
Rust
<br></br>
<br>
Self-closing.
HTML
[56, 78, 80
[56, 78, 80]
Close bracket.
Python
'info' + 62
'info' + str(62)
Can't add int to string.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(13);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(13, () => console.log('listening'));
Add callback.
Node.js
if (b = 70)
if (b == 70)
Use ==.
C++
<p>world <b>hello</p></b>
<p>world <b>hello</b></p>
Nest properly.
HTML
if c > 50 puts 'hello'
if c > 50 puts 'hello' end
Add 'end'.
Ruby
c == '15'
c === 15
Use strict equality.
JavaScript
values[100]
if values.indices.contains(100) {{ values[100] }}
Check index.
Swift
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
def bar(y): return y + 1
def bar(y): return y + 1
Correct.
Python
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
let text = String::from("hello"); let r=&text; text.push_str("!");
let mut text = String::from("hello"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
if (a = 32)
if (a == 32)
Use ==.
R
{{"title":"result" "id":82}}
{{"title":"result", "id":82}}
Add comma.
JSON
String y = 'message';
String y = "message";
Double quotes.
Java
val index = 80; index = 53
var index = 80; index = 53
Use var for reassignment.
Scala
if c > 35 print('data')
if c > 35: print('data')
Colon missing after if.
Python
if (x = 18) {{}}
if (x === 18) {{}}
Use === for equality.
JavaScript
let z = 57; z += 1;
let mut z = 57; z += 1;
Need mut to modify.
Rust
if [ $count = 50 ]; then
if [ "$count" = 50 ]; then
Quote variable.
Shell
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
{{"status":"info",}}
{{"status":"info"}}
Remove trailing comma.
JSON
val temp = 'message'
val temp = "message"
Double quotes.
Kotlin
List(26,53,84)
List(26,53,84)
Correct.
Scala