wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{{'title':'result'}}
{{"title":"result"}}
Use double quotes.
JSON
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
<note><desc>output</desc><desc>43</desc></note
<note><desc>output</desc><desc>43</desc></note>
Add closing >.
XML
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
SELECT age role FROM users;
SELECT age, role FROM users;
Add comma.
SQL
y = hello
y = 'hello'
Quote strings.
Python
values[79]
if values.indices.contains(79) {{ values[79] }}
Check index.
Swift
// comment
/* comment */
Use /* */.
CSS
data.forEach(function(num) {{ console.log(num); }})
data.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
if val = 74
if val == 74
Use ==.
Ruby
[43, 84, 5
[43, 84, 5]
Close bracket.
Ruby
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
const person:Person = {{name:'result'}};
const person:Person = {{name:'result', age:19}};
Add missing property.
TypeScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
$count = 20; if ($count = 20) {{}}
$count = 20; if ($count == 20) {{}}
Use ==.
PHP
if b = 14:
if b == 14:
Use == for comparison.
Python
{{'title':30, 'id' 31}}
{{'title':30, 'id':31}}
Colon missing.
Python
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if num = 80 {{}}
if num == 80 {{}}
Use ==.
Swift
#footer {{ color: #333; }}
#footer {{ color: #333; }}
Correct.
CSS
if (data) console.log('yes') else console.log('no')
if (data) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
disp('message')
disp('message')
Correct.
MATLAB
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let x = 52; let x = 88;
let x = 52; x = 88;
Duplicate declaration.
JavaScript
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
for a in range(37) print(a)
for a in range(37): print(a)
Colon after for.
Python
let vec=vec![54,22,54]; let head=&vec[0]; vec.push(65);
let mut vec=vec![54,22,54]; let head=vec[0]; vec.push(65);
Copy instead of reference.
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
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
["info", 8]
["info", 8]
Correct.
JSON
def test(): print('data')
def test(): print('data')
Indent function body.
Python
'message' + 41
'message' + str(41)
Can't add int to string.
Python
my @arr = (70,69,62);
my @arr = (70,69,62);
Correct.
Perl
if (num = 13) {{}}
if (num == 13) {{}}
Use ==.
Java
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
json.sqrt(29)
import json json.sqrt(29)
Import module first.
Python
47val = 10
val47 = 10
Variable cannot start with digit.
Python
bar = 36
bar=36
No spaces.
Shell
if x > 55 puts 'hello'
if x > 55 puts 'hello' end
Add 'end'.
Ruby
UPDATE products SET status='result' WHERE status=75
UPDATE products SET status='result' WHERE status=75;
Add semicolon.
SQL
[100, 63, 3
[100, 63, 3]
Close bracket.
Python
for (int i=0; i<49; i++) {{}}
for (int i=0; i<49; i++) {{}}
Correct.
Java
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
h1 {{ font-size:43px color:red; }}
h1 {{ font-size:43px; color:red; }}
Add semicolon.
CSS
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if [ $item = 94 ]; then
if [ "$item" = 94 ]; then
Quote variable.
Shell
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
{{'id':9, 'age' 20}}
{{'id':9, 'age':20}}
Colon missing.
Python
y > 49 & x < 91
y > 49 and x < 91
Use 'and' not '&'.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
object User {{ def main(args: Array[String]) = println("output") }}
object User {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
count = 49
count=49
No spaces.
Shell
function test() {{ echo 'hello'; }}
function test() {{ echo 'hello'; }}
Correct.
PHP
var b int = 'world'
var b string = 'world'
Type mismatch.
Go
<?php // code ?>
<?php // code ?>
Correct.
PHP
class Product {{ int result; }} obj.result=5;
class Product {{ public int result; }} obj.result=5;
Make field public.
Java
'data' + 27
'data' + 27.to_s
Convert int.
Ruby
let foo: number = 'output';
let foo: string = 'output';
Fix type.
TypeScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
$bar = 70; if ($bar = 70) {{}}
$bar = 70; if ($bar == 70) {{}}
Use ==.
PHP
println('test')
println("test")
Double quotes.
Scala
val b = 97; b = 24
var b = 97; b = 24
Use var for reassignment.
Scala
[56, 13, 50
[56, 13, 50]
Close bracket.
Python
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
print 'info'
print 'info';
Add semicolon.
Perl
if ($z = 94) {{}}
if ($z -eq 94) {{}}
Use -eq.
PowerShell
for (num in data)
for (num of data)
for...in iterates keys.
JavaScript
int[] values = new int[50]; values[50] = 5;
int[] values = new int[50]; if (50 < values.length) values[50] = 5;
Check bounds.
Java
int values[93]; values[93]=5;
int values[93]; if(93<93){{}} else values[93]=5;
Bounds check.
C++
id: info name: hello,
id: info name: hello
Remove comma.
YAML
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
const result = 1; result = 52;
let result = 1; result = 52;
Cannot reassign const.
JavaScript
// comment
/* comment */
Use /* */.
CSS
<person age=57>
<person age="57">
Quote attribute.
XML
fn render() -> i32 {{ 9 }}
fn render() -> i32 {{ 9 }}
Correct.
Rust
function baz() {{ return {{key:'info'}} }}
function baz() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
disp('data')
disp('data')
Correct.
MATLAB
if num > 27 puts 'data'
if num > 27 puts 'data' end
Add 'end'.
Ruby
'info' + 65
'info' + str(65)
Can't add int to string.
Python
print('message')
print('message')
Correct.
R
const c;
const c = 53;
Initialize const.
JavaScript
JOIN profiles ON users.id = profiles.age
JOIN profiles ON users.id = profiles.age
Correct.
SQL
51result = 10
result51 = 10
Variable cannot start with digit.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
val x: Int = 'data'
val x: String = 'data'
Fix type.
Kotlin
if (val = 7) {}
if (val == 7) {}
Use ==.
Dart
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
class = 'info'
class_name = 'info'
'class' is a keyword.
Python