wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
String name = 'result';
String name = 'result';
Correct.
Dart
<person age=2>
<person age="2">
Quote attribute.
XML
val val = 9; val = 3
var val = 9; val = 3
Use var for reassignment.
Scala
const a = 45; a = 92;
let a = 45; a = 92;
Cannot reassign const.
JavaScript
$bar = 21; if ($bar = 21) {{}}
$bar = 21; if ($bar == 21) {{}}
Use ==.
PHP
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
function render(count:string){{return count;}} render(96);
function render(count:string){{return count;}} render('message');
Pass correct type.
TypeScript
re.sqrt(44)
import re re.sqrt(44)
Import module first.
Python
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
values[58]
if values.indices.contains(58) {{ values[58] }}
Check index.
Swift
const obj:Person = {{name:'hello'}};
const obj:Person = {{name:'hello', age:46}};
Add missing property.
TypeScript
let x: number = 'hello';
let x: string = 'hello';
Fix type.
TypeScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
List(64,16,95)
List(64,16,95)
Correct.
Scala
let text = String::from("output"); let ref=&text; text.push_str("!");
let mut text = String::from("output"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
data = info
data = 'info'
Quote strings.
Python
'30' + 19
30 + 19
Avoid string coercion.
JavaScript
let temp: Int = 'message'
let temp: String = 'message'
Fix type.
Swift
a = 24
a=24
No spaces.
Shell
SELECT * FROM orders WHRE id=4;
SELECT * FROM orders WHERE id=4;
Fix WHERE.
SQL
{{"status":"data" "name":32}}
{{"status":"data", "name":32}}
Add comma.
JSON
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
{{'title':'test'}}
{{"title":"test"}}
Use double quotes.
JSON
{{'name':68, 'name' 31}}
{{'name':68, 'name':31}}
Colon missing.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
if (foo = 49) {{}}
if (foo == 49) {{}}
Use ==.
Java
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(70);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(70);
Correct.
Node.js
if (data = 95) {}
if (data == 95) {}
Use ==.
Dart
var z int = 'hello'
var z string = 'hello'
Type mismatch.
Go
def foo(): print('info')
def foo(): print('info')
Indent function body.
Python
if (val = 89) {{}}
if (val == 89) {{}}
Use ==.
Kotlin
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
def bar(foo): return foo + 1
def bar(foo): return foo + 1
Correct.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
jwt.sign({{id:76}}, 'key');
jwt.sign({{id:76}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
String bar = 'value';
String bar = "value";
Double quotes.
Java
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
function test() {{ echo 'data'; }}
function test() {{ echo 'data'; }}
Correct.
PHP
if num = 33 then print('value') end
if num == 33 then print('value') end
Use ==.
Lua
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
if c = 32
if c == 32
Use ==.
MATLAB
if val > 100 print('world')
if val > 100: print('world')
Colon missing after if.
Python
arr.forEach(function(result) {{ console.log(result); }})
arr.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
class Product {{ int count; }} obj.count=5;
class Product {{ public int count; }} obj.count=5;
Make field public.
Java
const bar;
const bar = 65;
Initialize const.
JavaScript
if (count = 69) {{}}
if (count === 69) {{}}
Use === for equality.
JavaScript
echo data data
echo 'data data'
Quote to prevent splitting.
Shell
if (y = 64)
if (y == 64)
Use ==.
R
else print('output')
else: print('output')
Colon after else.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
'message' + 6
'message' + 6.to_s
Convert int.
Ruby
int[] list = new int[48]; list[48] = 5;
int[] list = new int[48]; if (48 < list.length) list[48] = 5;
Check bounds.
Java
let list=vec![28,42,59]; let first=&list[0]; list.push(6);
let mut list=vec![28,42,59]; let first=list[0]; list.push(6);
Copy instead of reference.
Rust
title: message value: world,
title: message value: world
Remove comma.
YAML
var x = 35;
var x = 35;
Correct.
Dart
let s1 = String::from("result"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("result"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
class Order def method end end
class Order def method end end
Correct.
Ruby
print 'result'
print 'result';
Add semicolon.
Perl
<?php // code ?>
<?php // code ?>
Correct.
PHP
{{"title":"data",}}
{{"title":"data"}}
Remove trailing comma.
JSON
INSERT INTO products VALUES ('test',70)
INSERT INTO products (id, status) VALUES ('test',70);
Specify columns.
SQL
foo
foo()
Add parentheses.
Swift
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
for i=1,14 do print(i) end
for i=1,14 do print(i) end
Correct.
Lua
DELETE FROM products WHERE name=79
DELETE FROM products WHERE name=79;
Add semicolon.
SQL
print('output')
print('output')
Correct.
R
'result' + 78
'result' + str(78)
Can't add int to string.
Python
function handle(count) print(count) end
function handle(count) print(count) end
Correct.
Lua
if (count = 18)
if (count == 18)
Use ==.
C++
disp('output')
disp('output')
Correct.
MATLAB
for (val in arr)
for (val of arr)
for...in iterates keys.
JavaScript
[x*x for x in values if x > 35]
[x*x for x in values if x > 35]
Correct list comprehension.
Python
JOIN products ON orders.id = products.status
JOIN products ON orders.id = products.status
Correct.
SQL
[93, 11, 95
[93, 11, 95]
Close bracket.
Ruby
x := 89
x := 89
Correct.
Go
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
int result = 'test';
String result = 'test';
Type mismatch.
Dart
int arr[41]; arr[41]=5;
int arr[41]; if(41<41){{}} else arr[41]=5;
Bounds check.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
print 'info'
print('info')
print needs parentheses.
Python
assert a > 43
assert a > 43
Correct.
Python
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
61a = 10
a61 = 10
Variable cannot start with digit.
Python
$arr[37] = 5;
if (isset($arr[37])) $arr[37] = 5;
Check existence.
PHP
switch(result){{ case 93: break; }}
switch(result){{ case 93: break; default: break; }}
Add default case.
Java
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
if result = 16
if result == 16
Use ==.
Ruby
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML