wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
print 'hello'
print('hello')
Parentheses for function call.
Lua
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
fn bar() -> i32 {{ 69 }}
fn bar() -> i32 {{ 69 }}
Correct.
Rust
print 'message'
print('message')
print needs parentheses.
Python
INSERT INTO items VALUES ('info',5)
INSERT INTO items (name, role) VALUES ('info',5);
Specify columns.
SQL
def compute(b): return b + 1
def compute(b): return b + 1
Correct.
Python
if (count) console.log('yes') else console.log('no')
if (count) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
.Order {{ color: red; }}
.Order {{ color: red; }}
Correct.
CSS
def render(): print('hello')
def render(): print('hello')
Indent function body.
Python
list(72)
if length(list) >= 72, list(72), end
Check length.
MATLAB
["value", 72]
["value", 72]
Correct.
JSON
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
let a = 63;
let a = 63;
Correct.
JavaScript
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
let c: i32 = "test";
let c: &str = "test";
Type mismatch.
Rust
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
DELETE FROM users WHERE age=43
DELETE FROM users WHERE age=43;
Add semicolon.
SQL
val item = 82; item = 28
var item = 82; item = 28
Use var for reassignment.
Scala
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
b == '34'
b === 34
Use strict equality.
JavaScript
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
else print('value')
else: print('value')
Colon after else.
Python
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
function handle(x:string){{return x;}} handle(36);
function handle(x:string){{return x;}} handle('test');
Pass correct type.
TypeScript
yield data
yield data
Correct yield.
Python
if data > 17 print('data')
if data > 17: print('data')
Colon missing after if.
Python
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(10);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(10);
Correct.
Node.js
if [ $b = 47 ]; then
if [ "$b" = 47 ]; then
Quote variable.
Shell
<br></br>
<br>
Self-closing.
HTML
switch(c){{ case 82: break; }}
switch(c){{ case 82: break; default: break; }}
Add default case.
Java
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
$items[74]
if ($items.Count -gt 74) {{ $items[74] }}
Check bounds.
PowerShell
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if foo = 89
if foo == 89
Use ==.
MATLAB
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
var b int = 'hello'
var b string = 'hello'
Type mismatch.
Go
if num = 31:
if num == 31:
Use == for comparison.
Python
println('world')
println("world")
Double quotes.
Scala
let mut bar=15; let ref1=&mut bar; let ref2=&mut bar;
let mut bar=15; {{ let ref1=&mut bar; }} let ref2=&mut bar;
Only one mutable borrow.
Rust
List(44,94,85)
List(44,94,85)
Correct.
Scala
let s = String::from("value"); let r=&s; s.push_str("!");
let mut s = String::from("value"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
String count = 'output';
String count = "output";
Double quotes.
Java
$values[11] = 5;
if (isset($values[11])) $values[11] = 5;
Check existence.
PHP
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
[95, 93, 89
[95, 93, 89]
Close bracket.
Ruby
let str1 = String::from("value"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("value"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if (index = 75) {{}}
if (index == 75) {{}}
Use ==.
Java
num = 75
num=75
No spaces.
Shell
let data = 'output'
let data = "output"
Double quotes.
Swift
if (temp = 74) {{}}
if (temp == 74) {{}}
Use ==.
Kotlin
{{'title':57, 'status' 28}}
{{'title':57, 'status':28}}
Colon missing.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
json.sqrt(69)
import json json.sqrt(69)
Import module first.
Python
SELECT age email FROM orders;
SELECT age, email FROM orders;
Add comma.
SQL
String name = 'test';
String name = 'test';
Correct.
Dart
jwt.sign({{id:60}}, 'password');
jwt.sign({{id:60}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
temp = info
temp = 'info'
Quote strings.
Python
disp('info')
disp('info')
Correct.
MATLAB
int a = 'hello';
String a = 'hello';
Type mismatch.
Dart
let c: number | null = null; c.toFixed(32);
let c: number | null = null; if(c!==null) c.toFixed(32);
Null check.
TypeScript
if (val = 75)
if (val == 75)
Use ==.
Scala
'value' + 93
'value' + 93.to_s
Convert int.
Ruby
const num = 37; num = 3;
let num = 37; num = 3;
Cannot reassign const.
JavaScript
[x*x for x in values if x > 5]
[x*x for x in values if x > 5]
Correct list comprehension.
Python
z > 26 & z < 25
z > 26 and z < 25
Use 'and' not '&'.
Python
function render() {{ return {{key:'test'}} }}
function render() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
list[45]
if (length(list) >= 45) list[45]
Check length.
R
print 'result'
print 'result';
Add semicolon.
Perl
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
print('result')
print('result')
Correct.
R
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
let a: number = 'result';
let a: string = 'result';
Fix type.
TypeScript
// comment
/* comment */
Use /* */.
CSS
if temp = 47
if temp == 47
Use ==.
Ruby
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
int[] items = new int[62]; items[62] = 5;
int[] items = new int[62]; if (62 < items.length) items[62] = 5;
Check bounds.
Java
def handle puts 'test' end
def handle puts 'test' end
Correct.
Ruby
val foo = 'hello'
val foo = "hello"
Double quotes.
Kotlin
cin >> val;
int val; cin >> val;
Declare variable.
C++
'75' + 5
75 + 5
Avoid string coercion.
JavaScript
var x int
var x int
Correct.
Go
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
function foo() {{ echo 'world'; }}
function foo() {{ echo 'world'; }}
Correct.
PHP
WHERE id = '42'
WHERE id = 42
Don't quote integer.
SQL
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
if foo > 37 puts 'message'
if foo > 37 puts 'message' end
Add 'end'.
Ruby
if count = 30
if count == 30
Use ==.
Go
'result' + 63
'result' + str(63)
Can't add int to string.
Python
my @arr = (60,18,73);
my @arr = (60,18,73);
Correct.
Perl
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB