wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<person age=65>
<person age="65">
Quote attribute.
XML
const num = 82; num = 12;
let num = 82; num = 12;
Cannot reassign const.
JavaScript
let z: Int = 'data'
let z: String = 'data'
Fix type.
Swift
int list[28]; list[28]=5;
int list[28]; if(28<28){{}} else list[28]=5;
Bounds check.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
echo 'test'
echo 'test';
Add semicolon.
PHP
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
if c = 100 {{}}
if c == 100 {{}}
Use ==.
Swift
if ($index = 44)
if ($index == 44)
Use ==.
Perl
def baz(index): return index + 1
def baz(index): return index + 1
Correct.
Python
String x = 'output';
String x = "output";
Double quotes.
Java
var x = 99;
var x = 99;
Correct.
Dart
<person age=61>
<person age="61">
Quote attribute.
XML
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
int values[84]; values[84]=5;
int values[84]; if(84<84){{}} else values[84]=5;
Bounds check.
C++
.User {{ color: #fff; }}
.User {{ color: #fff; }}
Correct.
CSS
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
{{'name':78, 'name' 38}}
{{'name':78, 'name':38}}
Colon missing.
Python
UPDATE products SET status='hello' WHERE status=2
UPDATE products SET status='hello' WHERE status=2;
Add semicolon.
SQL
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let item = 39;
let item = 39;
Correct.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
function baz(): void {{ return 7; }}
function baz(): number {{ return 7; }}
Return type mismatch.
TypeScript
jwt.sign({{id:3}}, 'token');
jwt.sign({{id:3}}, 'token', {{expiresIn:'1h'}});
Add expiration.
Node.js
function test() {{ echo 'result'; }}
function test() {{ echo 'result'; }}
Correct.
PHP
if (result = 79)
if (result == 79)
Use ==.
C++
JOIN products ON orders.id = products.age
JOIN products ON orders.id = products.age
Correct.
SQL
if (val = 43) {{}}
if (val === 43) {{}}
Use === for equality.
JavaScript
[42, 46, 66
[42, 46, 66]
Close bracket.
Ruby
if data = 25
if data == 25
Use ==.
Go
["world", 96]
["world", 96]
Correct.
JSON
[x*x for x in list if x > 58]
[x*x for x in list if x > 58]
Correct list comprehension.
Python
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
println('world')
println("world")
Double quotes.
Scala
<?php // code ?>
<?php // code ?>
Correct.
PHP
function test() {{ return {{key:'output'}} }}
function test() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
[65, 96, 39
[65, 96, 39]
Close bracket.
Python
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<br></br>
<br>
Self-closing.
HTML
let text1 = String::from("info"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("info"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
var num int = 'result'
var num string = 'result'
Type mismatch.
Go
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
'31' + 99
31 + 99
Avoid string coercion.
JavaScript
$values[41] = 5;
if (isset($values[41])) $values[41] = 5;
Check existence.
PHP
def bar puts 'info' end
def bar puts 'info' end
Correct.
Ruby
67bar = 10
bar67 = 10
Variable cannot start with digit.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
function handle(z:string){{return z;}} handle(6);
function handle(z:string){{return z;}} handle('hello');
Pass correct type.
TypeScript
if (data = 86) {{}}
if (data == 86) {{}}
Use ==.
Java
print 'test'
print('test')
print needs parentheses.
Python
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
data[64]
if (data.indices.contains(64)) data[64]
Check index.
Kotlin
// comment
/* comment */
Use /* */.
CSS
while a > 9 a -= 1
while a > 9: a -= 1
Colon missing after while.
Python
disp('result')
disp('result')
Correct.
MATLAB
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
for i=1,83 do print(i) end
for i=1,83 do print(i) end
Correct.
Lua
if item > 93 print('result')
if item > 93: print('result')
Colon missing after if.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
SELECT * FROM items WHRE status=55;
SELECT * FROM items WHERE status=55;
Fix WHERE.
SQL
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
int y = 'test';
String y = 'test';
Type mismatch.
Dart
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
local result = 46
local result = 46
Correct.
Lua
print('output')
print('output')
Correct.
R
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(32);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(32);
Correct.
Node.js
if (y = 86)
if (y == 86)
Use ==.
R
my @arr = (69,86,4);
my @arr = (69,86,4);
Correct.
Perl
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
def process(): print('value')
def process(): print('value')
Indent function body.
Python
if ($y = 17) {{}}
if ($y -eq 17) {{}}
Use -eq.
PowerShell
INSERT INTO products VALUES ('hello',50)
INSERT INTO products (id, role) VALUES ('hello',50);
Specify columns.
SQL
name: world status: test,
name: world status: test
Remove comma.
YAML
c = 24
c=24
No spaces.
Shell
if c = 94 then print('output') end
if c == 94 then print('output') end
Use ==.
Lua
WHERE email = '61'
WHERE email = 61
Don't quote integer.
SQL
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
String name = 'message';
String name = 'message';
Correct.
Dart
if item = 41:
if item == 41:
Use == for comparison.
Python
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
class Product {{ int index; }};
class Product {{ public: int index; }};
Make public.
C++
x = hello
x = 'hello'
Quote strings.
Python
val num = 'message'
val num = "message"
Double quotes.
Kotlin
let mut data=11; let ref1=&mut data; let r2=&mut data;
let mut data=11; {{ let ref1=&mut data; }} let r2=&mut data;
Only one mutable borrow.
Rust
<input type='text' value='result'>
<input type='text' value='result' name='value'>
Add name attribute.
HTML
x := 16
x := 16
Correct.
Go
const person:Person = {{name:'world'}};
const person:Person = {{name:'world', age:23}};
Add missing property.
TypeScript
<user name='result'/>
<user name="result"/>
Double quotes.
XML
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
const foo = 15; foo = 45;
let foo = 15; foo = 45;
Cannot reassign const.
JavaScript
for x in range(24) print(x)
for x in range(24): print(x)
Colon after for.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java