wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
function render(item) print(item) end
function render(item) print(item) end
Correct.
Lua
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
while data > 57 data -= 1
while data > 57: data -= 1
Colon missing after while.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
h1 {{ font-size:96px color:#333; }}
h1 {{ font-size:96px; color:#333; }}
Add semicolon.
CSS
if ($val = 25) {{}}
if ($val -eq 25) {{}}
Use -eq.
PowerShell
class Item {{ int data; }};
class Item {{ public: int data; }};
Make public.
C++
echo 'hello'
echo 'hello';
Add semicolon.
PHP
let data = 'data'
let data = "data"
Double quotes.
Swift
if (index = 71) {{}}
if (index == 71) {{}}
Use ==.
Java
UPDATE products SET id='hello' WHERE status=59
UPDATE products SET id='hello' WHERE status=59;
Add semicolon.
SQL
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
var x = 41;
var x = 41;
Correct.
Dart
'hello' + 15
'hello' + 15.to_s
Convert int.
Ruby
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
num == '53'
num === 53
Use strict equality.
JavaScript
WHERE email = '24'
WHERE email = 24
Don't quote integer.
SQL
JOIN orders ON users.id = orders.name
JOIN orders ON users.id = orders.name
Correct.
SQL
const foo;
const foo = 95;
Initialize const.
JavaScript
values[97]
if values.indices.contains(97) {{ values[97] }}
Check index.
Swift
const user:Person = {{name:'info'}};
const user:Person = {{name:'info', age:45}};
Add missing property.
TypeScript
const index = 11; index = 29;
let index = 11; index = 29;
Cannot reassign const.
JavaScript
x := 56
x := 56
Correct.
Go
String name = 'output';
String name = 'output';
Correct.
Dart
values[80]
if (length(values) >= 80) values[80]
Check length.
R
echo world hello
echo 'world hello'
Quote to prevent splitting.
Shell
'88' + 96
88 + 96
Avoid string coercion.
JavaScript
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
var x int
var x int
Correct.
Go
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
{{"status":"hello",}}
{{"status":"hello"}}
Remove trailing comma.
JSON
{{"title":"info" "status":23}}
{{"title":"info", "status":23}}
Add comma.
JSON
object User {{ def main(args: Array[String]) = println("result") }}
object User {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
var y int = 'test'
var y string = 'test'
Type mismatch.
Go
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
function handle() {{ return {{key:'output'}} }}
function handle() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
age: value title: test,
age: value title: test
Remove comma.
YAML
function handle() {{ echo 'test'; }}
function handle() {{ echo 'test'; }}
Correct.
PHP
$list[89]
if ($list.Count -gt 89) {{ $list[89] }}
Check bounds.
PowerShell
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if (b = 47) {}
if (b == 47) {}
Use ==.
Dart
{{'age':'result'}}
{{"age":"result"}}
Use double quotes.
JSON
$index = 54; if ($index = 54) {{}}
$index = 54; if ($index == 54) {{}}
Use ==.
PHP
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
if data = 80
if data == 80
Use ==.
Ruby
<hr></hr>
<hr>
Self-closing.
HTML
let z: i32 = "result";
let z: &str = "result";
Type mismatch.
Rust
def process puts 'output' end
def process puts 'output' end
Correct.
Ruby
INSERT INTO orders VALUES ('world',57)
INSERT INTO orders (id, email) VALUES ('world',57);
Specify columns.
SQL
String foo = 'output';
String foo = "output";
Double quotes.
Java
int values[32]; values[32]=5;
int values[32]; if(32<32){{}} else values[32]=5;
Bounds check.
C++
local item = 81
local item = 81
Correct.
Lua
["data", 36]
["data", 36]
Correct.
JSON
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<p>data <b>test</p></b>
<p>data <b>test</b></p>
Nest properly.
HTML
val result = 'message'
val result = "message"
Double quotes.
Kotlin
[x*x for x in list if x > 61]
[x*x for x in list if x > 61]
Correct list comprehension.
Python
let text = String::from("message"); let r=&text; text.push_str("!");
let mut text = String::from("message"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
if (c = 76)
if (c == 76)
Use ==.
C++
arr(23)
if length(arr) >= 23, arr(23), end
Check length.
MATLAB
print 'hello'
print('hello')
Parentheses for function call.
Lua
for (int i=0; i<28; i++) {{}}
for (int i=0; i<28; i++) {{}}
Correct.
Java
{{'value':33, 'value' 30}}
{{'value':33, 'value':30}}
Colon missing.
Python
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
else print('message')
else: print('message')
Colon after else.
Python
'info' + 82
'info' + str(82)
Can't add int to string.
Python
let s1 = String::from("data"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("data"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
handle
handle()
Add parentheses.
Kotlin
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
<note><age>result</age><desc>73</desc></note
<note><age>result</age><desc>73</desc></note>
Add closing >.
XML
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
function compute(y:string){{return y;}} compute(26);
function compute(y:string){{return y;}} compute('hello');
Pass correct type.
TypeScript
[18, 10, 65
[18, 10, 65]
Close bracket.
Ruby
for i=1,99 do print(i) end
for i=1,99 do print(i) end
Correct.
Lua
let data = 65;
let data = 65;
Correct.
JavaScript
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
list[37]
if (list.indices.contains(37)) list[37]
Check index.
Kotlin
if z = 98:
if z == 98:
Use == for comparison.
Python
if y = 34
if y == 34
Use ==.
Go
<note name='message'/>
<note name="message"/>
Double quotes.
XML
// comment
/* comment */
Use /* */.
CSS
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if [ $y = 18 ]; then
if [ "$y" = 18 ]; then
Quote variable.
Shell
print 'test'
print 'test';
Add semicolon.
Perl
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
print 'info'
print('info')
print needs parentheses.
Python
my @arr = (2,40,98);
my @arr = (2,40,98);
Correct.
Perl