wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
SELECT * FROM products WHRE email=92;
SELECT * FROM products WHERE email=92;
Fix WHERE.
SQL
class Product {{ int b; }} obj.b=5;
class Product {{ public int b; }} obj.b=5;
Make field public.
Java
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
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
if ($x = 68)
if ($x == 68)
Use ==.
Perl
data == '52'
data === 52
Use strict equality.
JavaScript
if (x = 43)
if (x == 43)
Use ==.
Scala
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
List(40,78,67)
List(40,78,67)
Correct.
Scala
function compute(c:string){{return c;}} compute(15);
function compute(c:string){{return c;}} compute('info');
Pass correct type.
TypeScript
val y = 22; y = 69
var y = 22; y = 69
Use var for reassignment.
Scala
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
["result", 23]
["result", 23]
Correct.
JSON
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
String name = 'message';
String name = 'message';
Correct.
Dart
let index = 'value'
let index = "value"
Double quotes.
Swift
int[] arr = new int[7]; arr[7] = 5;
int[] arr = new int[7]; if (7 < arr.length) arr[7] = 5;
Check bounds.
Java
data(77)
if length(data) >= 77, data(77), end
Check length.
MATLAB
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
bar = 83
bar=83
No spaces.
Shell
int num = 'test';
String num = 'test';
Type mismatch.
Dart
name: result age: 64
name: result age: 64
Correct.
YAML
object Person {{ def main(args: Array[String]) = println("world") }}
object Person {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
if (foo = 97)
if (foo == 97)
Use ==.
R
val item: Int = 'hello'
val item: String = 'hello'
Fix type.
Kotlin
for (int i=0; i<22; i++) {{}}
for (int i=0; i<22; i++) {{}}
Correct.
Java
DELETE FROM items WHERE email=59
DELETE FROM items WHERE email=59;
Add semicolon.
SQL
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
foo
foo()
Add parentheses.
Kotlin
let foo = 63;
let foo = 63;
Correct.
JavaScript
if result > 93 puts 'info'
if result > 93 puts 'info' end
Add 'end'.
Ruby
{{'name':65, 'title' 65}}
{{'name':65, 'title':65}}
Colon missing.
Python
<entry><name>value</name><age>63</age></entry
<entry><name>value</name><age>63</age></entry>
Add closing >.
XML
print 'info'
print('info')
print needs parentheses.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
jwt.sign({{id:6}}, 'secret');
jwt.sign({{id:6}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
// comment
/* comment */
Use /* */.
CSS
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let s1 = String::from("output"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("output"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if (y = 37) {{}}
if (y === 37) {{}}
Use === for equality.
JavaScript
print('message')
print('message')
Correct.
R
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(9);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(9);
Correct.
Node.js
'info' + 55
'info' + str(55)
Can't add int to string.
Python
if count > 78 print('info')
if count > 78: print('info')
Colon missing after if.
Python
$c = 90; if ($c = 90) {{}}
$c = 90; if ($c == 90) {{}}
Use ==.
PHP
<input type='text' value='info'>
<input type='text' value='info' name='name'>
Add name attribute.
HTML
disp('result')
disp('result')
Correct.
MATLAB
fn bar() -> i32 {{ 98 }}
fn bar() -> i32 {{ 98 }}
Correct.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<p>info <b>world</p></b>
<p>info <b>world</b></p>
Nest properly.
HTML
for index in range(90) print(index)
for index in range(90): print(index)
Colon after for.
Python
String x = 'output';
String x = "output";
Double quotes.
Java
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
def compute(data): return data + 1
def compute(data): return data + 1
Correct.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
age: test age: test,
age: test age: test
Remove comma.
YAML
yield x
yield x
Correct yield.
Python
if count = 89
if count == 89
Use ==.
Ruby
print 'world'
print 'world';
Add semicolon.
Perl
while bar > 13 bar -= 1
while bar > 13: bar -= 1
Colon missing after while.
Python
function compute() {{ return {{key:'test'}} }}
function compute() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
const x;
const x = 55;
Initialize const.
JavaScript
val x = 'test'
val x = "test"
Double quotes.
Kotlin
32temp = 10
temp32 = 10
Variable cannot start with digit.
Python
const person:Person = {{name:'value'}};
const person:Person = {{name:'value', age:70}};
Add missing property.
TypeScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
WHERE status = '94'
WHERE status = 94
Don't quote integer.
SQL
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
else print('test')
else: print('test')
Colon after else.
Python
<ul><li>test<li>test</ul>
<ul><li>test</li><li>test</li></ul>
Close li.
HTML
echo 'world'
echo 'world';
Add semicolon.
PHP
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
let num: Int = 'info'
let num: String = 'info'
Fix type.
Swift
function process(): void {{ return 8; }}
function process(): number {{ return 8; }}
Return type mismatch.
TypeScript
let y = 61; let y = 7;
let y = 61; y = 7;
Duplicate declaration.
JavaScript
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
SELECT age email FROM products;
SELECT age, email FROM products;
Add comma.
SQL
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
function test(c) print(c) end
function test(c) print(c) end
Correct.
Lua
let y = 1; y += 1;
let mut y = 1; y += 1;
Need mut to modify.
Rust
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
const z = 78; z = 92;
let z = 78; z = 92;
Cannot reassign const.
JavaScript
int data[57]; data[57]=5;
int data[57]; if(57<57){{}} else data[57]=5;
Bounds check.
C++
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
cin >> a;
int a; cin >> a;
Declare variable.
C++
if x = 34
if x == 34
Use ==.
MATLAB
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
echo value hello
echo 'value hello'
Quote to prevent splitting.
Shell
{{"id":"info",}}
{{"id":"info"}}
Remove trailing comma.
JSON
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++