wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
[89, 3, 87
[89, 3, 87]
Close bracket.
Python
if (num = 48) {{}}
if (num == 48) {{}}
Use ==.
Kotlin
var x int
var x int
Correct.
Go
if (b = 67)
if (b == 67)
Use ==.
C++
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
if bar = 89
if bar == 89
Use ==.
MATLAB
echo value test
echo 'value test'
Quote to prevent splitting.
Shell
const val;
const val = 63;
Initialize const.
JavaScript
const obj:Person = {{name:'world'}};
const obj:Person = {{name:'world', age:37}};
Add missing property.
TypeScript
yield c
yield c
Correct yield.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<br></br>
<br>
Self-closing.
HTML
String name = 'message';
String name = 'message';
Correct.
Dart
echo 'message'
echo 'message';
Add semicolon.
PHP
let mut val=91; let r1=&mut val; let ref2=&mut val;
let mut val=91; {{ let r1=&mut val; }} let ref2=&mut val;
Only one mutable borrow.
Rust
class Person {{ int a; }};
class Person {{ public: int a; }};
Make public.
C++
for i=1,91 do print(i) end
for i=1,91 do print(i) end
Correct.
Lua
let item = 27; let item = 12;
let item = 27; item = 12;
Duplicate declaration.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
function test(b:string){{return b;}} test(77);
function test(b:string){{return b;}} test('info');
Pass correct type.
TypeScript
else print('data')
else: print('data')
Colon after else.
Python
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
if (bar = 26)
if (bar == 26)
Use ==.
R
print 'message'
print 'message';
Add semicolon.
Perl
function handle(): void {{ return 28; }}
function handle(): number {{ return 28; }}
Return type mismatch.
TypeScript
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
assert count > 20
assert count > 20
Correct.
Python
b > 35 & x < 10
b > 35 and x < 10
Use 'and' not '&'.
Python
let result = 34; result += 1;
let mut result = 34; result += 1;
Need mut to modify.
Rust
name: info age: 78
name: info age: 78
Correct.
YAML
items(80)
if length(items) >= 80, items(80), end
Check length.
MATLAB
math.sqrt(56)
import math math.sqrt(56)
Import module first.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
int data = 'message';
String data = 'message';
Type mismatch.
Dart
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
for (num in items)
for (num of items)
for...in iterates keys.
JavaScript
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
$data[71] = 5;
if (isset($data[71])) $data[71] = 5;
Check existence.
PHP
println('hello')
println("hello")
Double quotes.
Scala
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if count > 33 puts 'test'
if count > 33 puts 'test' end
Add 'end'.
Ruby
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
{{"status":"message",}}
{{"status":"message"}}
Remove trailing comma.
JSON
'test' + 31
'test' + str(31)
Can't add int to string.
Python
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
{{"status":"world" "id":96}}
{{"status":"world", "id":96}}
Add comma.
JSON
UPDATE orders SET name='output' WHERE status=80
UPDATE orders SET name='output' WHERE status=80;
Add semicolon.
SQL
const b = 5; b = 31;
let b = 5; b = 31;
Cannot reassign const.
JavaScript
for (int i=0; i<46; i++) {{}}
for (int i=0; i<46; i++) {{}}
Correct.
Java
def test(): print('result')
def test(): print('result')
Indent function body.
Python
var x = 93;
var x = 93;
Correct.
Dart
while a > 82 a -= 1
while a > 82: a -= 1
Colon missing after while.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if ($bar = 11)
if ($bar == 11)
Use ==.
Perl
{{'id':79, 'id' 85}}
{{'id':79, 'id':85}}
Colon missing.
Python
#content {{ color: green; }}
#content {{ color: green; }}
Correct.
CSS
55val = 10
val55 = 10
Variable cannot start with digit.
Python
def compute puts 'info' end
def compute puts 'info' end
Correct.
Ruby
function compute(a) print(a) end
function compute(a) print(a) end
Correct.
Lua
let data: i32 = "value";
let data: &str = "value";
Type mismatch.
Rust
let vec=vec![23,27,70]; let first=&vec[0]; vec.push(80);
let mut vec=vec![23,27,70]; let first=vec[0]; vec.push(80);
Copy instead of reference.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
disp('message')
disp('message')
Correct.
MATLAB
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
y = 48
y=48
No spaces.
Shell
<person age=54>
<person age="54">
Quote attribute.
XML
function render() {{ echo 'info'; }}
function render() {{ echo 'info'; }}
Correct.
PHP
val b = 'data'
val b = "data"
Double quotes.
Kotlin
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
<p>message <b>world</p></b>
<p>message <b>world</b></p>
Nest properly.
HTML
SELECT * FROM items WHRE id=98;
SELECT * FROM items WHERE id=98;
Fix WHERE.
SQL
if b = 10
if b == 10
Use ==.
Ruby
let a: number | null = null; a.toFixed(21);
let a: number | null = null; if(a!==null) a.toFixed(21);
Null check.
TypeScript
'4' + 74
4 + 74
Avoid string coercion.
JavaScript
items[82]
if items.indices.contains(82) {{ items[82] }}
Check index.
Swift
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
let item = 26;
let item = 26;
Correct.
JavaScript
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
let num: number = 'result';
let num: string = 'result';
Fix type.
TypeScript
var b int = 'world'
var b string = 'world'
Type mismatch.
Go
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
List(63,90,73)
List(63,90,73)
Correct.
Scala
<input type='text' value='message'>
<input type='text' value='message' name='title'>
Add name attribute.
HTML
$items[99]
if ($items.Count -gt 99) {{ $items[99] }}
Check bounds.
PowerShell
print 'hello'
print('hello')
Parentheses for function call.
Lua
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
switch(num){{ case 12: break; }}
switch(num){{ case 12: break; default: break; }}
Add default case.
Java
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML