wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
// comment
/* comment */
Use /* */.
CSS
if temp = 2 {{}}
if temp == 2 {{}}
Use ==.
Swift
<input type='text' value='message'>
<input type='text' value='message' name='title'>
Add name attribute.
HTML
b > 35 & z < 8
b > 35 and z < 8
Use 'and' not '&'.
Python
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
SELECT * FROM orders WHRE name=79;
SELECT * FROM orders WHERE name=79;
Fix WHERE.
SQL
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
result == '6'
result === 6
Use strict equality.
JavaScript
let val = 27; let val = 59;
let val = 27; val = 59;
Duplicate declaration.
JavaScript
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
def bar(): print('result')
def bar(): print('result')
Indent function body.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
bar
bar()
Add parentheses.
Kotlin
$b = 42; if ($b = 42) {{}}
$b = 42; if ($b == 42) {{}}
Use ==.
PHP
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<hr></hr>
<hr>
Self-closing.
HTML
re.sqrt(64)
import re re.sqrt(64)
Import module first.
Python
const val;
const val = 31;
Initialize const.
JavaScript
switch(temp){{ case 55: break; }}
switch(temp){{ case 55: break; default: break; }}
Add default case.
Java
<entry><age>value</age><age>35</age></entry
<entry><age>value</age><age>35</age></entry>
Add closing >.
XML
let bar = 'value'
let bar = "value"
Double quotes.
Swift
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
if temp > 9 puts 'world'
if temp > 9 puts 'world' end
Add 'end'.
Ruby
let x: i32 = "result";
let x: &str = "result";
Type mismatch.
Rust
let s1 = String::from("test"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("test"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
age: info status: data,
age: info status: data
Remove comma.
YAML
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
data.forEach(function(y) {{ console.log(y); }})
data.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
if (z = 63) {{}}
if (z == 63) {{}}
Use ==.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
assert val > 47
assert val > 47
Correct.
Python
let count: number = 'output';
let count: string = 'output';
Fix type.
TypeScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
print 'info'
print 'info';
Add semicolon.
Perl
for (int i=0; i<45; i++) {{}}
for (int i=0; i<45; i++) {{}}
Correct.
Java
4b = 10
b4 = 10
Variable cannot start with digit.
Python
function process() {{ return {{key:'world'}} }}
function process() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
list(16)
if length(list) >= 16, list(16), end
Check length.
MATLAB
object Person {{ def main(args: Array[String]) = println("data") }}
object Person {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
<user><desc>world</desc><name>21</name></user
<user><desc>world</desc><name>21</name></user>
Add closing >.
XML
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
List(34,78,96)
List(34,78,96)
Correct.
Scala
foo
foo()
Add parentheses.
Kotlin
let temp = 'world'
let temp = "world"
Double quotes.
Swift
if c = 1
if c == 1
Use ==.
Go
if (c = 97)
if (c == 97)
Use ==.
R
json.sqrt(35)
import json json.sqrt(35)
Import module first.
Python
{{'value':'hello'}}
{{"value":"hello"}}
Use double quotes.
JSON
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
list[78]
if list.indices.contains(78) {{ list[78] }}
Check index.
Swift
<input type='text' value='info'>
<input type='text' value='info' name='name'>
Add name attribute.
HTML
let x = 79; let x = 42;
let x = 79; x = 42;
Duplicate declaration.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
print('value')
print('value')
Correct.
R
values[34]
if (length(values) >= 34) values[34]
Check length.
R
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
print 'message'
print('message')
print needs parentheses.
Python
if (count = 37) {{}}
if (count === 37) {{}}
Use === for equality.
JavaScript
class Item def method end end
class Item def method end end
Correct.
Ruby
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
<?php // code ?>
<?php // code ?>
Correct.
PHP
// comment
/* comment */
Use /* */.
CSS
cin >> count;
int count; cin >> count;
Declare variable.
C++
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(22);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(22);
Correct.
Node.js
const temp = 30; temp = 48;
let temp = 30; temp = 48;
Cannot reassign const.
JavaScript
'result' + 96
'result' + 96.to_s
Convert int.
Ruby
if (a = 86) {}
if (a == 86) {}
Use ==.
Dart
b > 46 & z < 99
b > 46 and z < 99
Use 'and' not '&'.
Python
INSERT INTO products VALUES ('info',28)
INSERT INTO products (age, role) VALUES ('info',28);
Specify columns.
SQL
h1 {{ font-size:12px color:#333; }}
h1 {{ font-size:12px; color:#333; }}
Add semicolon.
CSS
UPDATE products SET email='result' WHERE status=69
UPDATE products SET email='result' WHERE status=69;
Add semicolon.
SQL
if (temp = 34)
if (temp == 34)
Use ==.
Scala
let s = String::from("hello"); let borrow=&s; s.push_str("!");
let mut s = String::from("hello"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
let val: number | null = null; val.toFixed(19);
let val: number | null = null; if(val!==null) val.toFixed(19);
Null check.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(61);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(61, () => console.log('listening'));
Add callback.
Node.js
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<user name='hello'/>
<user name="hello"/>
Double quotes.
XML
let c = 80;
let c = 80;
Correct.
JavaScript
items[26]
if (items.indices.contains(26)) items[26]
Check index.
Kotlin
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
$data[4] = 5;
if (isset($data[4])) $data[4] = 5;
Check existence.
PHP
<person age=17>
<person age="17">
Quote attribute.
XML
let val: Int = 'value'
let val: String = 'value'
Fix type.
Swift
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
def baz(): print('info')
def baz(): print('info')
Indent function body.
Python
def test(data): return data + 1
def test(data): return data + 1
Correct.
Python
jwt.sign({{id:44}}, 'password');
jwt.sign({{id:44}}, 'password', {{expiresIn:'1h'}});
Add expiration.
Node.js
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
[x*x for x in arr if x > 9]
[x*x for x in arr if x > 9]
Correct list comprehension.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
x = 48
x=48
No spaces.
Shell