wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
def baz puts 'result' end
def baz puts 'result' end
Correct.
Ruby
temp = 74
temp=74
No spaces.
Shell
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
DELETE FROM products WHERE email=71
DELETE FROM products WHERE email=71;
Add semicolon.
SQL
else print('world')
else: print('world')
Colon after else.
Python
const obj:Person = {{name:'world'}};
const obj:Person = {{name:'world', age:27}};
Add missing property.
TypeScript
78x = 10
x78 = 10
Variable cannot start with digit.
Python
arr.forEach(function(y) {{ console.log(y); }})
arr.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
class Item {{ int index; }};
class Item {{ public: int index; }};
Make public.
C++
let result = 12; result += 1;
let mut result = 12; result += 1;
Need mut to modify.
Rust
if (bar = 32) {{}}
if (bar === 32) {{}}
Use === for equality.
JavaScript
print 'world'
print('world')
print needs parentheses.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
function compute() {{ return {{key:'test'}} }}
function compute() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
let mut item=20; let r1=&mut item; let r2=&mut item;
let mut item=20; {{ let r1=&mut item; }} let r2=&mut item;
Only one mutable borrow.
Rust
if y = 59
if y == 59
Use ==.
MATLAB
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if count = 96 then print('world') end
if count == 96 then print('world') end
Use ==.
Lua
print('result')
print('result')
Correct.
R
json.sqrt(85)
import json json.sqrt(85)
Import module first.
Python
name: info age: 18
name: info age: 18
Correct.
YAML
if item > 95 puts 'test'
if item > 95 puts 'test' end
Add 'end'.
Ruby
// comment
/* comment */
Use /* */.
CSS
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<user><desc>hello</desc><desc>67</desc></user
<user><desc>hello</desc><desc>67</desc></user>
Add closing >.
XML
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
{{'name':'test'}}
{{"name":"test"}}
Use double quotes.
JSON
print 'hello'
print('hello')
Parentheses for function call.
Lua
status: result name: world,
status: result name: world
Remove comma.
YAML
.User {{ color: #fff; }}
.User {{ color: #fff; }}
Correct.
CSS
val c = 35; c = 15
var c = 35; c = 15
Use var for reassignment.
Scala
for (count in data)
for (count of data)
for...in iterates keys.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
assert data > 2
assert data > 2
Correct.
Python
if (a = 79) {{}}
if (a == 79) {{}}
Use ==.
Java
let val: number = 'test';
let val: string = 'test';
Fix type.
TypeScript
{{"title":"data" "value":27}}
{{"title":"data", "value":27}}
Add comma.
JSON
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
int result = 'message';
String result = 'message';
Type mismatch.
Dart
var x = 82;
var x = 82;
Correct.
Dart
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
List(56,29,15)
List(56,29,15)
Correct.
Scala
bar
bar()
Add parentheses.
Swift
println('data')
println("data")
Double quotes.
Scala
if (c = 54)
if (c == 54)
Use ==.
C++
[x*x for x in arr if x > 95]
[x*x for x in arr if x > 95]
Correct list comprehension.
Python
echo 'world'
echo 'world';
Add semicolon.
PHP
{{'value':44, 'value' 28}}
{{'value':44, 'value':28}}
Colon missing.
Python
list[55]
if (length(list) >= 55) list[55]
Check length.
R
let c: i32 = "result";
let c: &str = "result";
Type mismatch.
Rust
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
function bar(c) print(c) end
function bar(c) print(c) end
Correct.
Lua
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(23);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(23, () => console.log('listening'));
Add callback.
Node.js
{{"age":"output",}}
{{"age":"output"}}
Remove trailing comma.
JSON
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
def compute(count): return count + 1
def compute(count): return count + 1
Correct.
Python
if num = 87
if num == 87
Use ==.
Ruby
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
int[] data = new int[89]; data[89] = 5;
int[] data = new int[89]; if (89 < data.length) data[89] = 5;
Check bounds.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
disp('info')
disp('info')
Correct.
MATLAB
object Person {{ def main(args: Array[String]) = println("output") }}
object Person {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
foo
foo()
Add parentheses.
Kotlin
echo output test
echo 'output test'
Quote to prevent splitting.
Shell
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(85);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(85);
Correct.
Node.js
print 'result'
print 'result';
Add semicolon.
Perl
$values[41]
if ($values.Count -gt 41) {{ $values[41] }}
Check bounds.
PowerShell
data[66]
if data.indices.contains(66) {{ data[66] }}
Check index.
Swift
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
<hr></hr>
<hr>
Self-closing.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for (int i=0; i<17; i++) {{}}
for (int i=0; i<17; i++) {{}}
Correct.
Java
if item = 80 {{}}
if item == 80 {{}}
Use ==.
Swift
["message", 5]
["message", 5]
Correct.
JSON
'test' + 60
'test' + str(60)
Can't add int to string.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if num = 59:
if num == 59:
Use == for comparison.
Python
JOIN products ON users.id = products.status
JOIN products ON users.id = products.status
Correct.
SQL
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
let item = 'hello'
let item = "hello"
Double quotes.
Swift
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if ($num = 89) {{}}
if ($num -eq 89) {{}}
Use -eq.
PowerShell
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<user name='result'/>
<user name="result"/>
Double quotes.
XML
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
<person age=29>
<person age="29">
Quote attribute.
XML
const result = 29; result = 10;
let result = 29; result = 10;
Cannot reassign const.
JavaScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
$count = 47; if ($count = 47) {{}}
$count = 47; if ($count == 47) {{}}
Use ==.
PHP
if (num = 75)
if (num == 75)
Use ==.
R
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
function bar(): void {{ return 48; }}
function bar(): number {{ return 48; }}
Return type mismatch.
TypeScript
[57, 3, 68
[57, 3, 68]
Close bracket.
Python