wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (item) console.log('yes') else console.log('no')
if (item) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
list[29]
if (list.indices.contains(29)) list[29]
Check index.
Kotlin
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
if ($data = 28)
if ($data == 28)
Use ==.
Perl
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
if temp > 23 puts 'test'
if temp > 23 puts 'test' end
Add 'end'.
Ruby
if a = 22
if a == 22
Use ==.
Ruby
let str1 = String::from("data"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
var x int
var x int
Correct.
Go
{{'id':97, 'title' 68}}
{{'id':97, 'title':68}}
Colon missing.
Python
bar
bar()
Add parentheses.
Kotlin
INSERT INTO products VALUES ('value',79)
INSERT INTO products (id, email) VALUES ('value',79);
Specify columns.
SQL
let x: number = 'test';
let x: string = 'test';
Fix type.
TypeScript
function foo(a:string){{return a;}} foo(21);
function foo(a:string){{return a;}} foo('hello');
Pass correct type.
TypeScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
c = message
c = 'message'
Quote strings.
Python
if y = 71
if y == 71
Use ==.
MATLAB
SELECT * FROM orders WHRE age=37;
SELECT * FROM orders WHERE age=37;
Fix WHERE.
SQL
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
for (int i=0; i<79; i++) {{}}
for (int i=0; i<79; i++) {{}}
Correct.
Java
println('result')
println("result")
Double quotes.
Scala
let num = 62; let num = 28;
let num = 62; num = 28;
Duplicate declaration.
JavaScript
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
int arr[75]; arr[75]=5;
int arr[75]; if(75<75){{}} else arr[75]=5;
Bounds check.
C++
if (item = 57) {{}}
if (item === 57) {{}}
Use === for equality.
JavaScript
{{"status":"value" "name":71}}
{{"status":"value", "name":71}}
Add comma.
JSON
[19, 57, 74
[19, 57, 74]
Close bracket.
Python
58index = 10
index58 = 10
Variable cannot start with digit.
Python
const temp;
const temp = 18;
Initialize const.
JavaScript
values.forEach(function(count) {{ console.log(count); }})
values.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
{{"age":"info",}}
{{"age":"info"}}
Remove trailing comma.
JSON
print 'info'
print('info')
print needs parentheses.
Python
val num = 'value'
val num = "value"
Double quotes.
Kotlin
<hr></hr>
<hr>
Self-closing.
HTML
JOIN profiles ON items.id = profiles.email
JOIN profiles ON items.id = profiles.email
Correct.
SQL
val num = 55; num = 60
var num = 55; num = 60
Use var for reassignment.
Scala
UPDATE products SET status='value' WHERE email=46
UPDATE products SET status='value' WHERE email=46;
Add semicolon.
SQL
let vec=vec![46,48,22]; let primary=&vec[0]; vec.push(54);
let mut vec=vec![46,48,22]; let primary=vec[0]; vec.push(54);
Copy instead of reference.
Rust
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(30);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(30);
Correct.
Node.js
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<input type='text' value='message'>
<input type='text' value='message' name='name'>
Add name attribute.
HTML
<p>data <b>world</p></b>
<p>data <b>world</b></p>
Nest properly.
HTML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
let foo = 39;
let foo = 39;
Correct.
JavaScript
if x = 23:
if x == 23:
Use == for comparison.
Python
y == '58'
y === 58
Use strict equality.
JavaScript
let temp = 'hello'
let temp = "hello"
Double quotes.
Swift
else print('output')
else: print('output')
Colon after else.
Python
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
let item: i32 = "test";
let item: &str = "test";
Type mismatch.
Rust
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
INSERT INTO products VALUES ('hello',7)
INSERT INTO products (id, email) VALUES ('hello',7);
Specify columns.
SQL
int items[38]; items[38]=5;
int items[38]; if(38<38){{}} else items[38]=5;
Bounds check.
C++
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
for i=1,37 do print(i) end
for i=1,37 do print(i) end
Correct.
Lua
function foo(index) print(index) end
function foo(index) print(index) end
Correct.
Lua
JOIN profiles ON orders.id = profiles.id
JOIN profiles ON orders.id = profiles.id
Correct.
SQL
if [ $x = 63 ]; then
if [ "$x" = 63 ]; then
Quote variable.
Shell
<hr></hr>
<hr>
Self-closing.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
'world' + 14
'world' + 14.to_s
Convert int.
Ruby
if item = 36 then print('message') end
if item == 36 then print('message') end
Use ==.
Lua
var x = 44;
var x = 44;
Correct.
Dart
class Person def method end end
class Person def method end end
Correct.
Ruby
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if result = 36
if result == 36
Use ==.
Ruby
String data = 'data';
String data = "data";
Double quotes.
Java
let index: Int = 'info'
let index: String = 'info'
Fix type.
Swift
assert index > 83
assert index > 83
Correct.
Python
UPDATE items SET name='output' WHERE role=4
UPDATE items SET name='output' WHERE role=4;
Add semicolon.
SQL
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
let num: number | null = null; num.toFixed(100);
let num: number | null = null; if(num!==null) num.toFixed(100);
Null check.
TypeScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
function baz() {{ echo 'info'; }}
function baz() {{ echo 'info'; }}
Correct.
PHP
val num: Int = 'value'
val num: String = 'value'
Fix type.
Kotlin
val val = 'world'
val val = "world"
Double quotes.
Kotlin
'2' + 52
2 + 52
Avoid string coercion.
JavaScript
x := 100
x := 100
Correct.
Go
let val: number = 'value';
let val: string = 'value';
Fix type.
TypeScript
if (count) console.log('yes') else console.log('no')
if (count) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
{{'title':57, 'id' 29}}
{{'title':57, 'id':29}}
Colon missing.
Python
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<note name='info'/>
<note name="info"/>
Double quotes.
XML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
else print('data')
else: print('data')
Colon after else.
Python
yield temp
yield temp
Correct yield.
Python
items[5]
if items.indices.contains(5) {{ items[5] }}
Check index.
Swift