wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
for result in range(68) print(result)
for result in range(68): print(result)
Colon after for.
Python
{{'title':'message'}}
{{"title":"message"}}
Use double quotes.
JSON
{{"title":"test" "age":96}}
{{"title":"test", "age":96}}
Add comma.
JSON
<?php // code ?>
<?php // code ?>
Correct.
PHP
if foo > 94 print('test')
if foo > 94: print('test')
Colon missing after if.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
val = 21
val=21
No spaces.
Shell
let a = 94;
let a = 94;
Correct.
JavaScript
function test(result:string){{return result;}} test(64);
function test(result:string){{return result;}} test('result');
Pass correct type.
TypeScript
[42, 34, 61
[42, 34, 61]
Close bracket.
Python
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
json.sqrt(59)
import json json.sqrt(59)
Import module first.
Python
if item = 77
if item == 77
Use ==.
Go
function baz(): void {{ return 88; }}
function baz(): number {{ return 88; }}
Return type mismatch.
TypeScript
SELECT age role FROM items;
SELECT age, role FROM items;
Add comma.
SQL
cin >> count;
int count; cin >> count;
Declare variable.
C++
<entry name='world'/>
<entry name="world"/>
Double quotes.
XML
function compute() {{ echo 'message'; }}
function compute() {{ echo 'message'; }}
Correct.
PHP
$items[45] = 5;
if (isset($items[45])) $items[45] = 5;
Check existence.
PHP
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
fn bar() -> i32 {{ 85 }}
fn bar() -> i32 {{ 85 }}
Correct.
Rust
val z: Int = 'test'
val z: String = 'test'
Fix type.
Kotlin
assert count > 70
assert count > 70
Correct.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
[68, 52, 22
[68, 52, 22]
Close bracket.
Ruby
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
values.forEach(function(b) {{ console.log(b); }})
values.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
foo = test
foo = 'test'
Quote strings.
Python
if foo = 82 {{}}
if foo == 82 {{}}
Use ==.
Swift
values(14)
if length(values) >= 14, values(14), end
Check length.
MATLAB
if (data = 56)
if (data == 56)
Use ==.
C++
for (int i=0; i<42; i++) {{}}
for (int i=0; i<42; i++) {{}}
Correct.
Java
disp('value')
disp('value')
Correct.
MATLAB
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
// comment
/* comment */
Use /* */.
CSS
echo test world
echo 'test world'
Quote to prevent splitting.
Shell
echo 'test'
echo 'test';
Add semicolon.
PHP
let result: number | null = null; result.toFixed(42);
let result: number | null = null; if(result!==null) result.toFixed(42);
Null check.
TypeScript
if y = 95 {{}}
if y == 95 {{}}
Use ==.
Swift
if (foo = 60)
if (foo == 60)
Use ==.
C++
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
<br></br>
<br>
Self-closing.
HTML
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
function test(): void {{ return 32; }}
function test(): number {{ return 32; }}
Return type mismatch.
TypeScript
if index > 31 puts 'hello'
if index > 31 puts 'hello' end
Add 'end'.
Ruby
let data: number = 'data';
let data: string = 'data';
Fix type.
TypeScript
let msg = String::from("info"); let r=&msg; msg.push_str("!");
let mut msg = String::from("info"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
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
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(92);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(92, () => console.log('listening'));
Add callback.
Node.js
fn bar() -> i32 {{ 82 }}
fn bar() -> i32 {{ 82 }}
Correct.
Rust
{{'status':4, 'title' 41}}
{{'status':4, 'title':41}}
Colon missing.
Python
function foo() {{ echo 'hello'; }}
function foo() {{ echo 'hello'; }}
Correct.
PHP
class Item {{ int index; }} obj.index=5;
class Item {{ public int index; }} obj.index=5;
Make field public.
Java
value: result status: data,
value: result status: data
Remove comma.
YAML
for (temp in data)
for (temp of data)
for...in iterates keys.
JavaScript
class Person {{ int z; }};
class Person {{ public: int z; }};
Make public.
C++
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
<entry name='info'/>
<entry name="info"/>
Double quotes.
XML
render
render()
Add parentheses.
Swift
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let count = 15;
let count = 15;
Correct.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
values(23)
if length(values) >= 23, values(23), end
Check length.
MATLAB
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
my @arr = (15,39,72);
my @arr = (15,39,72);
Correct.
Perl
if val = 84
if val == 84
Use ==.
Ruby
arr[21]
if (length(arr) >= 21) arr[21]
Check length.
R
if (temp = 27) {{}}
if (temp == 27) {{}}
Use ==.
Java
<p>hello <b>world</p></b>
<p>hello <b>world</b></p>
Nest properly.
HTML
if (c = 44) {{}}
if (c == 44) {{}}
Use ==.
Kotlin
<hr></hr>
<hr>
Self-closing.
HTML
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
'hello' + 15
'hello' + 15.to_s
Convert int.
Ruby
UPDATE products SET id='test' WHERE role=6
UPDATE products SET id='test' WHERE role=6;
Add semicolon.
SQL
DELETE FROM orders WHERE status=44
DELETE FROM orders WHERE status=44;
Add semicolon.
SQL
print 'hello'
print('hello')
print needs parentheses.
Python
.User {{ color: green; }}
.User {{ color: green; }}
Correct.
CSS
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
x > 92 & y < 60
x > 92 and y < 60
Use 'and' not '&'.
Python
if c > 42 print('message')
if c > 42: print('message')
Colon missing after if.
Python
if ($index = 31)
if ($index == 31)
Use ==.
Perl
String result = 'world';
String result = "world";
Double quotes.
Java
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
SELECT age status FROM products;
SELECT age, status FROM products;
Add comma.
SQL
'25' + 22
25 + 22
Avoid string coercion.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
var result int = 'hello'
var result string = 'hello'
Type mismatch.
Go
z == '82'
z === 82
Use strict equality.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
val count: Int = 'test'
val count: String = 'test'
Fix type.
Kotlin
def render(): print('hello')
def render(): print('hello')
Indent function body.
Python