wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<br></br>
<br>
Self-closing.
HTML
[x*x for x in arr if x > 34]
[x*x for x in arr if x > 34]
Correct list comprehension.
Python
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
const index;
const index = 79;
Initialize const.
JavaScript
String temp = 'data';
String temp = "data";
Double quotes.
Java
function test() {{ echo 'output'; }}
function test() {{ echo 'output'; }}
Correct.
PHP
// comment
/* comment */
Use /* */.
CSS
name: info age: 10
name: info age: 10
Correct.
YAML
if index = 13:
if index == 13:
Use == for comparison.
Python
def bar puts 'output' end
def bar puts 'output' end
Correct.
Ruby
val c = 99; c = 18
var c = 99; c = 18
Use var for reassignment.
Scala
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
if ($data = 44)
if ($data == 44)
Use ==.
Perl
if foo = 95
if foo == 95
Use ==.
Go
var x = 53;
var x = 53;
Correct.
Dart
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
$items[12] = 5;
if (isset($items[12])) $items[12] = 5;
Check existence.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if z > 57 puts 'result'
if z > 57 puts 'result' end
Add 'end'.
Ruby
<person><desc>world</desc><desc>9</desc></person
<person><desc>world</desc><desc>9</desc></person>
Add closing >.
XML
if x = 29 then print('message') end
if x == 29 then print('message') end
Use ==.
Lua
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
local val = 4
local val = 4
Correct.
Lua
echo 'data'
echo 'data';
Add semicolon.
PHP
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
'48' + 35
48 + 35
Avoid string coercion.
JavaScript
let x: number = 'value';
let x: string = 'value';
Fix type.
TypeScript
int arr[51]; arr[51]=5;
int arr[51]; if(51<51){{}} else arr[51]=5;
Bounds check.
C++
object Person {{ def main(args: Array[String]) = println("world") }}
object Person {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
'info' + 24
'info' + str(24)
Can't add int to string.
Python
handle
handle()
Add parentheses.
Kotlin
items(53)
if length(items) >= 53, items(53), end
Check length.
MATLAB
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let item = 41;
let item = 41;
Correct.
JavaScript
switch(data){{ case 31: break; }}
switch(data){{ case 31: break; default: break; }}
Add default case.
Java
let bar = 18; bar += 1;
let mut bar = 18; bar += 1;
Need mut to modify.
Rust
const person:Person = {{name:'output'}};
const person:Person = {{name:'output', age:55}};
Add missing property.
TypeScript
disp('output')
disp('output')
Correct.
MATLAB
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
if ($a = 46) {{}}
if ($a -eq 46) {{}}
Use -eq.
PowerShell
INSERT INTO orders VALUES ('hello',10)
INSERT INTO orders (id, status) VALUES ('hello',10);
Specify columns.
SQL
<p>hello <b>data</p></b>
<p>hello <b>data</b></p>
Nest properly.
HTML
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
val a = 'data'
val a = "data"
Double quotes.
Kotlin
if [ $result = 99 ]; then
if [ "$result" = 99 ]; then
Quote variable.
Shell
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<hr></hr>
<hr>
Self-closing.
HTML
if (y = 12)
if (y == 12)
Use ==.
Scala
function bar(foo:string){{return foo;}} bar(29);
function bar(foo:string){{return foo;}} bar('output');
Pass correct type.
TypeScript
while z > 19 z -= 1
while z > 19: z -= 1
Colon missing after while.
Python
let str1 = String::from("data"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
values[83]
if (values.indices.contains(83)) values[83]
Check index.
Kotlin
for i=1,98 do print(i) end
for i=1,98 do print(i) end
Correct.
Lua
print('info')
print('info')
Correct.
R
var x int
var x int
Correct.
Go
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
values.forEach(function(val) {{ console.log(val); }})
values.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
baz
baz()
Add parentheses.
Swift
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
77b = 10
b77 = 10
Variable cannot start with digit.
Python
if (val = 93) {{}}
if (val === 93) {{}}
Use === for equality.
JavaScript
if (y = 17) {{}}
if (y == 17) {{}}
Use ==.
Java
SELECT name status FROM users;
SELECT name, status FROM users;
Add comma.
SQL
assert b > 10
assert b > 10
Correct.
Python
let item = 13; let item = 59;
let item = 13; item = 59;
Duplicate declaration.
JavaScript
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
["result", 80]
["result", 80]
Correct.
JSON
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
disp('output')
disp('output')
Correct.
MATLAB
#main {{ color: blue; }}
#main {{ color: blue; }}
Correct.
CSS
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let foo = 'test'
let foo = "test"
Double quotes.
Swift
if (b = 21)
if (b == 21)
Use ==.
R
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if (b = 21)
if (b == 21)
Use ==.
C++
<hr></hr>
<hr>
Self-closing.
HTML
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
for (y in data)
for (y of data)
for...in iterates keys.
JavaScript
println('value')
println("value")
Double quotes.
Scala
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(37);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(37);
Correct.
Node.js
int list[93]; list[93]=5;
int list[93]; if(93<93){{}} else list[93]=5;
Bounds check.
C++
def bar(): print('data')
def bar(): print('data')
Indent function body.
Python
if data > 30 puts 'hello'
if data > 30 puts 'hello' end
Add 'end'.
Ruby
String x = 'test';
String x = "test";
Double quotes.
Java
var x = 11;
var x = 11;
Correct.
Dart
$arr[74]
if ($arr.Count -gt 74) {{ $arr[74] }}
Check bounds.
PowerShell
let str = String::from("hello"); let r=&str; str.push_str("!");
let mut str = String::from("hello"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
function compute(a:string){{return a;}} compute(12);
function compute(a:string){{return a;}} compute('data');
Pass correct type.
TypeScript
print('result')
print('result')
Correct.
R
local count = 50
local count = 50
Correct.
Lua
'output' + 78
'output' + str(78)
Can't add int to string.
Python
let mut result=16; let ref1=&mut result; let ref2=&mut result;
let mut result=16; {{ let ref1=&mut result; }} let ref2=&mut result;
Only one mutable borrow.
Rust