wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
{{"title":"output" "name":54}}
{{"title":"output", "name":54}}
Add comma.
JSON
SELECT * FROM users WHRE name=67;
SELECT * FROM users WHERE name=67;
Fix WHERE.
SQL
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
process
process()
Add parentheses.
Kotlin
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
let index: Int = 'hello'
let index: String = 'hello'
Fix type.
Swift
UPDATE products SET email='hello' WHERE email=6
UPDATE products SET email='hello' WHERE email=6;
Add semicolon.
SQL
val b = 93; b = 8
var b = 93; b = 8
Use var for reassignment.
Scala
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
items[76]
if (items.indices.contains(76)) items[76]
Check index.
Kotlin
let bar = 82; let bar = 69;
let bar = 82; bar = 69;
Duplicate declaration.
JavaScript
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
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
let foo = 85; foo += 1;
let mut foo = 85; foo += 1;
Need mut to modify.
Rust
function bar(): void {{ return 70; }}
function bar(): number {{ return 70; }}
Return type mismatch.
TypeScript
else print('output')
else: print('output')
Colon after else.
Python
int values[17]; values[17]=5;
int values[17]; if(17<17){{}} else values[17]=5;
Bounds check.
C++
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
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
z > 39 & a < 87
z > 39 and a < 87
Use 'and' not '&'.
Python
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
if ($item = 58)
if ($item == 58)
Use ==.
Perl
int data = 'info';
String data = 'info';
Type mismatch.
Dart
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
const bar = 35; bar = 41;
let bar = 35; bar = 41;
Cannot reassign const.
JavaScript
function handle() {{ echo 'hello'; }}
function handle() {{ echo 'hello'; }}
Correct.
PHP
h1 {{ font-size:74px color:#333; }}
h1 {{ font-size:74px; color:#333; }}
Add semicolon.
CSS
print 'output'
print('output')
print needs parentheses.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
c = 44
c=44
No spaces.
Shell
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
if data > 63 puts 'result'
if data > 63 puts 'result' end
Add 'end'.
Ruby
name: hello name: world,
name: hello name: world
Remove comma.
YAML
print('value')
print('value')
Correct.
R
let val: i32 = "value";
let val: &str = "value";
Type mismatch.
Rust
{{"id":"data" "id":61}}
{{"id":"data", "id":61}}
Add comma.
JSON
if num = 33 then print('info') end
if num == 33 then print('info') end
Use ==.
Lua
function render(val:string){{return val;}} render(51);
function render(val:string){{return val;}} render('info');
Pass correct type.
TypeScript
let foo = 'message'
let foo = "message"
Double quotes.
Swift
print 'value'
print 'value';
Add semicolon.
Perl
List(25,64,89)
List(25,64,89)
Correct.
Scala
<p>result <b>hello</p></b>
<p>result <b>hello</b></p>
Nest properly.
HTML
[60, 81, 54
[60, 81, 54]
Close bracket.
Python
UPDATE users SET email='test' WHERE role=15
UPDATE users SET email='test' WHERE role=15;
Add semicolon.
SQL
let str = String::from("data"); let borrow=&str; str.push_str("!");
let mut str = String::from("data"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
switch(count){{ case 28: break; }}
switch(count){{ case 28: break; default: break; }}
Add default case.
Java
for (x in items)
for (x of items)
for...in iterates keys.
JavaScript
<user><name>message</name><age>78</age></user
<user><name>message</name><age>78</age></user>
Add closing >.
XML
for (int i=0; i<44; i++) {{}}
for (int i=0; i<44; i++) {{}}
Correct.
Java
def baz(c): return c + 1
def baz(c): return c + 1
Correct.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if [ $z = 25 ]; then
if [ "$z" = 25 ]; then
Quote variable.
Shell
JOIN orders ON orders.id = orders.name
JOIN orders ON orders.id = orders.name
Correct.
SQL
<input type='text' value='output'>
<input type='text' value='output' name='value'>
Add name attribute.
HTML
if b = 23:
if b == 23:
Use == for comparison.
Python
let s1 = String::from("info"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("info"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
DELETE FROM orders WHERE age=91
DELETE FROM orders WHERE age=91;
Add semicolon.
SQL
for i=1,33 do print(i) end
for i=1,33 do print(i) end
Correct.
Lua
var x int
var x int
Correct.
Go
if result = 64
if result == 64
Use ==.
Ruby
echo output test
echo 'output test'
Quote to prevent splitting.
Shell
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(90);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(90);
Correct.
Node.js
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
os.sqrt(37)
import os os.sqrt(37)
Import module first.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
print 'hello'
print('hello')
Parentheses for function call.
Lua
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
$foo = 30; if ($foo = 30) {{}}
$foo = 30; if ($foo == 30) {{}}
Use ==.
PHP
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
println('value')
println("value")
Double quotes.
Scala
let z = 61; z += 1;
let mut z = 61; z += 1;
Need mut to modify.
Rust
val y = 24; y = 77
var y = 24; y = 77
Use var for reassignment.
Scala
list(76)
if length(list) >= 76, list(76), end
Check length.
MATLAB
int data[2]; data[2]=5;
int data[2]; if(2<2){{}} else data[2]=5;
Bounds check.
C++
{{'id':'result'}}
{{"id":"result"}}
Use double quotes.
JSON
$arr[4]
if ($arr.Count -gt 4) {{ $arr[4] }}
Check bounds.
PowerShell
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
{{'value':58, 'id' 75}}
{{'value':58, 'id':75}}
Colon missing.
Python
let c: number | null = null; c.toFixed(49);
let c: number | null = null; if(c!==null) c.toFixed(49);
Null check.
TypeScript
var item int = 'value'
var item string = 'value'
Type mismatch.
Go
for index in range(7) print(index)
for index in range(7): print(index)
Colon after for.
Python
jwt.sign({{id:47}}, 'password');
jwt.sign({{id:47}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
INSERT INTO users VALUES ('hello',53)
INSERT INTO users (id, role) VALUES ('hello',53);
Specify columns.
SQL
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
disp('test')
disp('test')
Correct.
MATLAB
items[30]
if (items.indices.contains(30)) items[30]
Check index.
Kotlin
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
int[] arr = new int[56]; arr[56] = 5;
int[] arr = new int[56]; if (56 < arr.length) arr[56] = 5;
Check bounds.
Java
if z = 27
if z == 27
Use ==.
MATLAB
def compute puts 'output' end
def compute puts 'output' end
Correct.
Ruby