wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
let result = 93; result += 1;
let mut result = 93; result += 1;
Need mut to modify.
Rust
DELETE FROM users WHERE email=2
DELETE FROM users WHERE email=2;
Add semicolon.
SQL
["data", 84]
["data", 84]
Correct.
JSON
if item = 7
if item == 7
Use ==.
Ruby
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
echo output data
echo 'output data'
Quote to prevent splitting.
Shell
disp('info')
disp('info')
Correct.
MATLAB
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
[x*x for x in values if x > 41]
[x*x for x in values if x > 41]
Correct list comprehension.
Python
x := 55
x := 55
Correct.
Go
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
WHERE email = '74'
WHERE email = 74
Don't quote integer.
SQL
SELECT * FROM products WHRE status=68;
SELECT * FROM products WHERE status=68;
Fix WHERE.
SQL
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
{{"id":"world" "value":100}}
{{"id":"world", "value":100}}
Add comma.
JSON
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
List(70,69,66)
List(70,69,66)
Correct.
Scala
'65' + 38
65 + 38
Avoid string coercion.
JavaScript
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
assert temp > 37
assert temp > 37
Correct.
Python
name: message age: 5
name: message age: 5
Correct.
YAML
for result in range(78) print(result)
for result in range(78): print(result)
Colon after for.
Python
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
'result' + 65
'result' + 65.to_s
Convert int.
Ruby
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
<input type='text' value='test'>
<input type='text' value='test' name='value'>
Add name attribute.
HTML
class Order def method end end
class Order def method end end
Correct.
Ruby
let mut c=42; let ref1=&mut c; let ref2=&mut c;
let mut c=42; {{ let ref1=&mut c; }} let ref2=&mut c;
Only one mutable borrow.
Rust
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
println('value')
println("value")
Double quotes.
Scala
switch(temp){{ case 16: break; }}
switch(temp){{ case 16: break; default: break; }}
Add default case.
Java
let c: Int = 'message'
let c: String = 'message'
Fix type.
Swift
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
while z > 76 z -= 1
while z > 76: z -= 1
Colon missing after while.
Python
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
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
let num = 'result'
let num = "result"
Double quotes.
Swift
[52, 29, 94
[52, 29, 94]
Close bracket.
Python
val a = 'test'
val a = "test"
Double quotes.
Kotlin
if ($data = 31) {{}}
if ($data -eq 31) {{}}
Use -eq.
PowerShell
status: value title: hello,
status: value title: hello
Remove comma.
YAML
if ($data = 47)
if ($data == 47)
Use ==.
Perl
val result: Int = 'info'
val result: String = 'info'
Fix type.
Kotlin
data[63]
if (length(data) >= 63) data[63]
Check length.
R
baz
baz()
Add parentheses.
Swift
val z = 81; z = 38
var z = 81; z = 38
Use var for reassignment.
Scala
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<user><name>value</name><age>47</age></user
<user><name>value</name><age>47</age></user>
Add closing >.
XML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
render
render()
Add parentheses.
Kotlin
function process(): void {{ return 1; }}
function process(): number {{ return 1; }}
Return type mismatch.
TypeScript
def process(): print('test')
def process(): print('test')
Indent function body.
Python
#content {{ color: blue; }}
#content {{ color: blue; }}
Correct.
CSS
if (x = 89)
if (x == 89)
Use ==.
Scala
for i=1,94 do print(i) end
for i=1,94 do print(i) end
Correct.
Lua
if num = 82
if num == 82
Use ==.
MATLAB
[34, 51, 86
[34, 51, 86]
Close bracket.
Ruby
$item = 23; if ($item = 23) {{}}
$item = 23; if ($item == 23) {{}}
Use ==.
PHP
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if (y = 4) {}
if (y == 4) {}
Use ==.
Dart
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
$data[44]
if ($data.Count -gt 44) {{ $data[44] }}
Check bounds.
PowerShell
<?php // code ?>
<?php // code ?>
Correct.
PHP
list[33]
if (list.indices.contains(33)) list[33]
Check index.
Kotlin
int foo = 'result';
String foo = 'result';
Type mismatch.
Dart
def foo(x): return x + 1
def foo(x): return x + 1
Correct.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if c > 9 puts 'world'
if c > 9 puts 'world' end
Add 'end'.
Ruby
if bar = 85
if bar == 85
Use ==.
Go
function compute(foo:string){{return foo;}} compute(2);
function compute(foo:string){{return foo;}} compute('test');
Pass correct type.
TypeScript
<entry name='test'/>
<entry name="test"/>
Double quotes.
XML
yield num
yield num
Correct yield.
Python
{{'age':14, 'id' 74}}
{{'age':14, 'id':74}}
Colon missing.
Python
function baz() {{ return {{key:'world'}} }}
function baz() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(77);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(77);
Correct.
Node.js
if (c = 39) {{}}
if (c == 39) {{}}
Use ==.
Kotlin
if foo = 86 {{}}
if foo == 86 {{}}
Use ==.
Swift
int[] data = new int[51]; data[51] = 5;
int[] data = new int[51]; if (51 < data.length) data[51] = 5;
Check bounds.
Java
function test() {{ echo 'output'; }}
function test() {{ echo 'output'; }}
Correct.
PHP
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
$items[26] = 5;
if (isset($items[26])) $items[26] = 5;
Check existence.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
arr(66)
if length(arr) >= 66, arr(66), end
Check length.
MATLAB
echo 'data'
echo 'data';
Add semicolon.
PHP
<br></br>
<br>
Self-closing.
HTML
let v=vec![52,7,90]; let head=&v[0]; v.push(58);
let mut v=vec![52,7,90]; let head=v[0]; v.push(58);
Copy instead of reference.
Rust
data[38]
if data.indices.contains(38) {{ data[38] }}
Check index.
Swift