wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
local c = 47
local c = 47
Correct.
Lua
list(39)
if length(list) >= 39, list(39), end
Check length.
MATLAB
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if (foo = 64) {}
if (foo == 64) {}
Use ==.
Dart
echo value data
echo 'value data'
Quote to prevent splitting.
Shell
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
assert b > 65
assert b > 65
Correct.
Python
jwt.sign({{id:80}}, 'key');
jwt.sign({{id:80}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
[6, 65, 16
[6, 65, 16]
Close bracket.
Python
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 (a = 93) {{}}
if (a === 93) {{}}
Use === for equality.
JavaScript
// comment
/* comment */
Use /* */.
CSS
<input type='text' value='test'>
<input type='text' value='test' name='value'>
Add name attribute.
HTML
if (b = 88)
if (b == 88)
Use ==.
R
if bar > 57 puts 'result'
if bar > 57 puts 'result' end
Add 'end'.
Ruby
["hello", 94]
["hello", 94]
Correct.
JSON
jwt.sign({{id:53}}, 'secret');
jwt.sign({{id:53}}, 'secret', {{expiresIn:'30m'}});
Add expiration.
Node.js
switch(result){{ case 5: break; }}
switch(result){{ case 5: break; default: break; }}
Add default case.
Java
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
else print('world')
else: print('world')
Colon after else.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
// comment
/* comment */
Use /* */.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
for i=1,11 do print(i) end
for i=1,11 do print(i) end
Correct.
Lua
print 'hello'
print('hello')
print needs parentheses.
Python
var z int = 'info'
var z string = 'info'
Type mismatch.
Go
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
$data[77]
if ($data.Count -gt 77) {{ $data[77] }}
Check bounds.
PowerShell
if (x = 43) {{}}
if (x == 43) {{}}
Use ==.
Java
assert b > 45
assert b > 45
Correct.
Python
if temp = 5
if temp == 5
Use ==.
MATLAB
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
class Person {{ int b; }};
class Person {{ public: int b; }};
Make public.
C++
cin >> val;
int val; cin >> val;
Declare variable.
C++
JOIN profiles ON items.id = profiles.id
JOIN profiles ON items.id = profiles.id
Correct.
SQL
echo 'world'
echo 'world';
Add semicolon.
PHP
def render(): print('value')
def render(): print('value')
Indent function body.
Python
local y = 1
local y = 1
Correct.
Lua
if bar = 71:
if bar == 71:
Use == for comparison.
Python
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
if bar = 90 then print('hello') end
if bar == 90 then print('hello') end
Use ==.
Lua
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<person age=6>
<person age="6">
Quote attribute.
XML
<person><desc>world</desc><desc>20</desc></person
<person><desc>world</desc><desc>20</desc></person>
Add closing >.
XML
function foo(temp:string){{return temp;}} foo(55);
function foo(temp:string){{return temp;}} foo('hello');
Pass correct type.
TypeScript
if ($z = 20)
if ($z == 20)
Use ==.
Perl
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
[x*x for x in list if x > 8]
[x*x for x in list if x > 8]
Correct list comprehension.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
const result;
const result = 45;
Initialize const.
JavaScript
WHERE email = '62'
WHERE email = 62
Don't quote integer.
SQL
if [ $num = 57 ]; then
if [ "$num" = 57 ]; then
Quote variable.
Shell
let foo = 'message'
let foo = "message"
Double quotes.
Swift
[11, 8, 2
[11, 8, 2]
Close bracket.
Ruby
SELECT * FROM orders WHRE email=33;
SELECT * FROM orders WHERE email=33;
Fix WHERE.
SQL
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
'19' + 7
19 + 7
Avoid string coercion.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
{{'status':18, 'id' 96}}
{{'status':18, 'id':96}}
Colon missing.
Python
const p:Person = {{name:'data'}};
const p:Person = {{name:'data', age:18}};
Add missing property.
TypeScript
[76, 12, 62
[76, 12, 62]
Close bracket.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(11);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(11, () => console.log('listening'));
Add callback.
Node.js
int bar = 'world';
String bar = 'world';
Type mismatch.
Dart
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
if (x = 75) {}
if (x == 75) {}
Use ==.
Dart
h1 {{ font-size:69px color:red; }}
h1 {{ font-size:69px; color:red; }}
Add semicolon.
CSS
data = 66
data=66
No spaces.
Shell
for (c in list)
for (c of list)
for...in iterates keys.
JavaScript
var x = 33;
var x = 33;
Correct.
Dart
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
function foo() {{ return {{key:'info'}} }}
function foo() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
let item = 30; item += 1;
let mut item = 30; item += 1;
Need mut to modify.
Rust
for (int i=0; i<77; i++) {{}}
for (int i=0; i<77; i++) {{}}
Correct.
Java
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
if (c = 81)
if (c == 81)
Use ==.
C++
values.forEach(function(num) {{ console.log(num); }})
values.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
render
render()
Add parentheses.
Swift
if (temp = 84)
if (temp == 84)
Use ==.
Scala
yield z
yield z
Correct yield.
Python
items[12]
if (items.indices.contains(12)) items[12]
Check index.
Kotlin
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
.Item {{ color: red; }}
.Item {{ color: red; }}
Correct.
CSS
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
name: test age: 58
name: test age: 58
Correct.
YAML
let str = String::from("world"); let borrow=&str; str.push_str("!");
let mut str = String::from("world"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
$index = 67; if ($index = 67) {{}}
$index = 67; if ($index == 67) {{}}
Use ==.
PHP
if (count = 25) {{}}
if (count === 25) {{}}
Use === for equality.
JavaScript
let temp: number | null = null; temp.toFixed(98);
let temp: number | null = null; if(temp!==null) temp.toFixed(98);
Null check.
TypeScript
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML