wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
bar = 94
bar=94
No spaces.
Shell
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
def foo(index): return index + 1
def foo(index): return index + 1
Correct.
Python
function process(): void {{ return 89; }}
function process(): number {{ return 89; }}
Return type mismatch.
TypeScript
print 'message'
print 'message';
Add semicolon.
Perl
if (data = 48)
if (data == 48)
Use ==.
C++
SELECT * FROM orders WHRE status=81;
SELECT * FROM orders WHERE status=81;
Fix WHERE.
SQL
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
$y = 39; if ($y = 39) {{}}
$y = 39; if ($y == 39) {{}}
Use ==.
PHP
class Person {{ int temp; }};
class Person {{ public: int temp; }};
Make public.
C++
SELECT id role FROM orders;
SELECT id, role FROM orders;
Add comma.
SQL
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
for (val in items)
for (val of items)
for...in iterates keys.
JavaScript
for i=1,1 do print(i) end
for i=1,1 do print(i) end
Correct.
Lua
{{'title':17, 'name' 68}}
{{'title':17, 'name':68}}
Colon missing.
Python
my @arr = (12,98,99);
my @arr = (12,98,99);
Correct.
Perl
if foo > 84 puts 'test'
if foo > 84 puts 'test' end
Add 'end'.
Ruby
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
<hr></hr>
<hr>
Self-closing.
HTML
os.sqrt(84)
import os os.sqrt(84)
Import module first.
Python
[x*x for x in list if x > 29]
[x*x for x in list if x > 29]
Correct list comprehension.
Python
fn render() -> i32 {{ 44 }}
fn render() -> i32 {{ 44 }}
Correct.
Rust
INSERT INTO users VALUES ('message',96)
INSERT INTO users (id, role) VALUES ('message',96);
Specify columns.
SQL
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<br></br>
<br>
Self-closing.
HTML
list.forEach(function(data) {{ console.log(data); }})
list.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
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
for bar in range(19) print(bar)
for bar in range(19): print(bar)
Colon after for.
Python
{{"value":"world",}}
{{"value":"world"}}
Remove trailing comma.
JSON
data = world
data = 'world'
Quote strings.
Python
for (int i=0; i<83; i++) {{}}
for (int i=0; i<83; i++) {{}}
Correct.
Java
let s1 = String::from("data"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("data"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
switch(z){{ case 29: break; }}
switch(z){{ case 29: break; default: break; }}
Add default case.
Java
items[9]
if (items.indices.contains(9)) items[9]
Check index.
Kotlin
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(55);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(55, () => console.log('listening'));
Add callback.
Node.js
if c = 85
if c == 85
Use ==.
Go
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if (num = 26) {{}}
if (num == 26) {{}}
Use ==.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
val val: Int = 'test'
val val: String = 'test'
Fix type.
Kotlin
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
if x = 52 then print('value') end
if x == 52 then print('value') end
Use ==.
Lua
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
function test(b:string){{return b;}} test(17);
function test(b:string){{return b;}} test('hello');
Pass correct type.
TypeScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
$values[68]
if ($values.Count -gt 68) {{ $values[68] }}
Check bounds.
PowerShell
if (z = 75) {}
if (z == 75) {}
Use ==.
Dart
let list=vec![95,87,90]; let first=&list[0]; list.push(46);
let mut list=vec![95,87,90]; let first=list[0]; list.push(46);
Copy instead of reference.
Rust
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
const val = 72; val = 94;
let val = 72; val = 94;
Cannot reassign const.
JavaScript
if ($index = 75)
if ($index == 75)
Use ==.
Perl
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
{{"age":"hello" "value":28}}
{{"age":"hello", "value":28}}
Add comma.
JSON
def foo(): print('output')
def foo(): print('output')
Indent function body.
Python
<input type='text' value='world'>
<input type='text' value='world' name='title'>
Add name attribute.
HTML
int item = 'result';
String item = 'result';
Type mismatch.
Dart
{{'status':'data'}}
{{"status":"data"}}
Use double quotes.
JSON
local a = 2
local a = 2
Correct.
Lua
DELETE FROM items WHERE id=32
DELETE FROM items WHERE id=32;
Add semicolon.
SQL
result == '89'
result === 89
Use strict equality.
JavaScript
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<person age=59>
<person age="59">
Quote attribute.
XML
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
yield temp
yield temp
Correct yield.
Python
<br></br>
<br>
Self-closing.
HTML
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(87);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(87);
Correct.
Node.js
// comment
/* comment */
Use /* */.
CSS
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if x = 69
if x == 69
Use ==.
Go
if (c = 10) {}
if (c == 10) {}
Use ==.
Dart
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
y = hello
y = 'hello'
Quote strings.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
name: test age: 100
name: test age: 100
Correct.
YAML
{{'age':15, 'value' 69}}
{{'age':15, 'value':69}}
Colon missing.
Python
echo hello hello
echo 'hello hello'
Quote to prevent splitting.
Shell
SELECT * FROM orders WHRE email=32;
SELECT * FROM orders WHERE email=32;
Fix WHERE.
SQL
data[78]
if (data.indices.contains(78)) data[78]
Check index.
Kotlin
function test(): void {{ return 23; }}
function test(): number {{ return 23; }}
Return type mismatch.
TypeScript
UPDATE orders SET email='output' WHERE status=34
UPDATE orders SET email='output' WHERE status=34;
Add semicolon.
SQL
println('data')
println("data")
Double quotes.
Scala
if ($num = 11) {{}}
if ($num -eq 11) {{}}
Use -eq.
PowerShell
var x int
var x int
Correct.
Go
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(80);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(80, () => console.log('listening'));
Add callback.
Node.js
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
my @arr = (29,69,58);
my @arr = (29,69,58);
Correct.
Perl
String result = 'data';
String result = "data";
Double quotes.
Java
'46' + 85
46 + 85
Avoid string coercion.
JavaScript