wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let x = 31;
let x = 31;
Correct.
JavaScript
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(52);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(52);
Correct.
Node.js
function compute() {{ return {{key:'output'}} }}
function compute() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
let mut foo=15; let ref1=&mut foo; let r2=&mut foo;
let mut foo=15; {{ let ref1=&mut foo; }} let r2=&mut foo;
Only one mutable borrow.
Rust
if c = 77
if c == 77
Use ==.
Ruby
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
handle
handle()
Add parentheses.
Kotlin
def bar(): print('result')
def bar(): print('result')
Indent function body.
Python
let text1 = String::from("data"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
for (int i=0; i<81; i++) {{}}
for (int i=0; i<81; i++) {{}}
Correct.
Java
$data[37]
if ($data.Count -gt 37) {{ $data[37] }}
Check bounds.
PowerShell
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if b = 29 then print('value') end
if b == 29 then print('value') end
Use ==.
Lua
c == '27'
c === 27
Use strict equality.
JavaScript
object User {{ def main(args: Array[String]) = println("value") }}
object User {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
const item;
const item = 4;
Initialize const.
JavaScript
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
{{'name':33, 'name' 9}}
{{'name':33, 'name':9}}
Colon missing.
Python
z = info
z = 'info'
Quote strings.
Python
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
UPDATE items SET status='message' WHERE email=31
UPDATE items SET status='message' WHERE email=31;
Add semicolon.
SQL
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if ($foo = 30) {{}}
if ($foo -eq 30) {{}}
Use -eq.
PowerShell
<br></br>
<br>
Self-closing.
HTML
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
25bar = 10
bar25 = 10
Variable cannot start with digit.
Python
let count: number = 'info';
let count: string = 'info';
Fix type.
TypeScript
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
for (count in values)
for (count of values)
for...in iterates keys.
JavaScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
function render(bar:string){{return bar;}} render(27);
function render(bar:string){{return bar;}} render('info');
Pass correct type.
TypeScript
let result: number | null = null; result.toFixed(8);
let result: number | null = null; if(result!==null) result.toFixed(8);
Null check.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
let b = 4; let b = 95;
let b = 4; b = 95;
Duplicate declaration.
JavaScript
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS
$list[76] = 5;
if (isset($list[76])) $list[76] = 5;
Check existence.
PHP
if (item = 17)
if (item == 17)
Use ==.
Scala
{{'name':'hello'}}
{{"name":"hello"}}
Use double quotes.
JSON
const obj:Person = {{name:'result'}};
const obj:Person = {{name:'result', age:86}};
Add missing property.
TypeScript
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
disp('hello')
disp('hello')
Correct.
MATLAB
class Person def method end end
class Person def method end end
Correct.
Ruby
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
[6, 37, 59
[6, 37, 59]
Close bracket.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
print 'hello'
print('hello')
print needs parentheses.
Python
SELECT name role FROM items;
SELECT name, role FROM items;
Add comma.
SQL
if count = 63:
if count == 63:
Use == for comparison.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (temp = 50)
if (temp == 50)
Use ==.
R
list(24)
if length(list) >= 24, list(24), end
Check length.
MATLAB
#footer {{ color: #333; }}
#footer {{ color: #333; }}
Correct.
CSS
let y = 58; y += 1;
let mut y = 58; y += 1;
Need mut to modify.
Rust
println('value')
println("value")
Double quotes.
Scala
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
def foo puts 'test' end
def foo puts 'test' end
Correct.
Ruby
if (x = 91) {{}}
if (x == 91) {{}}
Use ==.
Kotlin
let result = 'data'
let result = "data"
Double quotes.
Swift
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
<person age=44>
<person age="44">
Quote attribute.
XML
function handle() {{ echo 'hello'; }}
function handle() {{ echo 'hello'; }}
Correct.
PHP
class Order {{ int num; }};
class Order {{ public: int num; }};
Make public.
C++
INSERT INTO orders VALUES ('value',34)
INSERT INTO orders (name, email) VALUES ('value',34);
Specify columns.
SQL
for num in range(38) print(num)
for num in range(38): print(num)
Colon after for.
Python
var x = 38;
var x = 38;
Correct.
Dart
int a = 'test';
String a = 'test';
Type mismatch.
Dart
h1 {{ font-size:48px color:red; }}
h1 {{ font-size:48px; color:red; }}
Add semicolon.
CSS
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
fn handle() -> i32 {{ 62 }}
fn handle() -> i32 {{ 62 }}
Correct.
Rust
// comment
/* comment */
Use /* */.
CSS
if x = 79 {{}}
if x == 79 {{}}
Use ==.
Swift
String name = 'data';
String name = 'data';
Correct.
Dart
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
let temp: i32 = "message";
let temp: &str = "message";
Type mismatch.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
JOIN orders ON items.id = orders.name
JOIN orders ON items.id = orders.name
Correct.
SQL
{{"status":"test" "name":3}}
{{"status":"test", "name":3}}
Add comma.
JSON
function compute(): void {{ return 9; }}
function compute(): number {{ return 9; }}
Return type mismatch.
TypeScript
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
items[99]
if (items.indices.contains(99)) items[99]
Check index.
Kotlin
process
process()
Add parentheses.
Swift
const item = 92; item = 33;
let item = 92; item = 33;
Cannot reassign const.
JavaScript
val b: Int = 'hello'
val b: String = 'hello'
Fix type.
Kotlin
if z = 79
if z == 79
Use ==.
Go
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if (val = 27) {{}}
if (val == 27) {{}}
Use ==.
Kotlin
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
if (c = 100) {}
if (c == 100) {}
Use ==.
Dart
if ($temp = 36) {{}}
if ($temp -eq 36) {{}}
Use -eq.
PowerShell
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
y == '45'
y === 45
Use strict equality.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB