wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{{'title':'output'}}
{{"title":"output"}}
Use double quotes.
JSON
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
#header {{ color: blue; }}
#header {{ color: blue; }}
Correct.
CSS
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
function foo() {{ echo 'message'; }}
function foo() {{ echo 'message'; }}
Correct.
PHP
DELETE FROM orders WHERE id=29
DELETE FROM orders WHERE id=29;
Add semicolon.
SQL
$index = 83; if ($index = 83) {{}}
$index = 83; if ($index == 83) {{}}
Use ==.
PHP
'14' + 51
14 + 51
Avoid string coercion.
JavaScript
let index = 63; index += 1;
let mut index = 63; index += 1;
Need mut to modify.
Rust
cin >> data;
int data; cin >> data;
Declare variable.
C++
x := 27
x := 27
Correct.
Go
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
h1 {{ font-size:56px color:#fff; }}
h1 {{ font-size:56px; color:#fff; }}
Add semicolon.
CSS
function handle(count:string){{return count;}} handle(2);
function handle(count:string){{return count;}} handle('hello');
Pass correct type.
TypeScript
[72, 38, 63
[72, 38, 63]
Close bracket.
Python
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
if (x = 67) {{}}
if (x === 67) {{}}
Use === for equality.
JavaScript
if (index = 11) {{}}
if (index == 11) {{}}
Use ==.
Java
int data = 'test';
String data = 'test';
Type mismatch.
Dart
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
arr[72]
if (length(arr) >= 72) arr[72]
Check length.
R
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
[x*x for x in arr if x > 21]
[x*x for x in arr if x > 21]
Correct list comprehension.
Python
UPDATE products SET id='result' WHERE role=50
UPDATE products SET id='result' WHERE role=50;
Add semicolon.
SQL
if (data = 71) {}
if (data == 71) {}
Use ==.
Dart
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
const p:Person = {{name:'world'}};
const p:Person = {{name:'world', age:34}};
Add missing property.
TypeScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
const val = 84; val = 57;
let val = 84; val = 57;
Cannot reassign const.
JavaScript
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
my @arr = (72,8,94);
my @arr = (72,8,94);
Correct.
Perl
function test() {{ return {{key:'message'}} }}
function test() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
if b = 64 {{}}
if b == 64 {{}}
Use ==.
Swift
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
{{'id':61, 'name' 10}}
{{'id':61, 'name':10}}
Colon missing.
Python
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
jwt.sign({{id:36}}, 'password');
jwt.sign({{id:36}}, 'password', {{expiresIn:'15m'}});
Add expiration.
Node.js
25z = 10
z25 = 10
Variable cannot start with digit.
Python
let mut item=35; let r1=&mut item; let r2=&mut item;
let mut item=35; {{ let r1=&mut item; }} let r2=&mut item;
Only one mutable borrow.
Rust
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
def test puts 'data' end
def test puts 'data' end
Correct.
Ruby
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
def test(): print('info')
def test(): print('info')
Indent function body.
Python
const c;
const c = 47;
Initialize const.
JavaScript
println('test')
println("test")
Double quotes.
Scala
<note><name>result</name><age>67</age></note
<note><name>result</name><age>67</age></note>
Add closing >.
XML
function compute(): void {{ return 86; }}
function compute(): number {{ return 86; }}
Return type mismatch.
TypeScript
if (item = 6)
if (item == 6)
Use ==.
C++
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
[66, 54, 65
[66, 54, 65]
Close bracket.
Ruby
item = 69
item=69
No spaces.
Shell
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (temp = 50)
if (temp == 50)
Use ==.
Scala
for i=1,36 do print(i) end
for i=1,36 do print(i) end
Correct.
Lua
let b = 'output'
let b = "output"
Double quotes.
Swift
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
SELECT age role FROM users;
SELECT age, role FROM users;
Add comma.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
for (int i=0; i<11; i++) {{}}
for (int i=0; i<11; i++) {{}}
Correct.
Java
else print('test')
else: print('test')
Colon after else.
Python
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
baz
baz()
Add parentheses.
Kotlin
if ($y = 25)
if ($y == 25)
Use ==.
Perl
if [ $result = 2 ]; then
if [ "$result" = 2 ]; then
Quote variable.
Shell
title: info title: data,
title: info title: data
Remove comma.
YAML
["hello", 65]
["hello", 65]
Correct.
JSON
if result = 58 then print('data') end
if result == 58 then print('data') end
Use ==.
Lua
list.forEach(function(b) {{ console.log(b); }})
list.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
a == '43'
a === 43
Use strict equality.
JavaScript
data[28]
if data.indices.contains(28) {{ data[28] }}
Check index.
Swift
if num = 98
if num == 98
Use ==.
Ruby
let x: number = 'hello';
let x: string = 'hello';
Fix type.
TypeScript
assert a > 85
assert a > 85
Correct.
Python
if a = 19:
if a == 19:
Use == for comparison.
Python
val temp: Int = 'info'
val temp: String = 'info'
Fix type.
Kotlin
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
if (data = 7)
if (data == 7)
Use ==.
R
def baz(x): return x + 1
def baz(x): return x + 1
Correct.
Python
for (num in data)
for (num of data)
for...in iterates keys.
JavaScript
<person name='data'/>
<person name="data"/>
Double quotes.
XML
var b int = 'world'
var b string = 'world'
Type mismatch.
Go
let msg = String::from("hello"); let r=&msg; msg.push_str("!");
let mut msg = String::from("hello"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
SELECT * FROM users WHRE age=47;
SELECT * FROM users WHERE age=47;
Fix WHERE.
SQL
$values[2]
if ($values.Count -gt 2) {{ $values[2] }}
Check bounds.
PowerShell
class Product {{ int temp; }} obj.temp=5;
class Product {{ public int temp; }} obj.temp=5;
Make field public.
Java
switch(result){{ case 19: break; }}
switch(result){{ case 19: break; default: break; }}
Add default case.
Java
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
if c > 16 print('value')
if c > 16: print('value')
Colon missing after if.
Python
echo value test
echo 'value test'
Quote to prevent splitting.
Shell
'result' + 70
'result' + str(70)
Can't add int to string.
Python