wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
#header {{ color: #333; }}
#header {{ color: #333; }}
Correct.
CSS
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
let result: i32 = "data";
let result: &str = "data";
Type mismatch.
Rust
let list=vec![16,74,82]; let first=&list[0]; list.push(3);
let mut list=vec![16,74,82]; let first=list[0]; list.push(3);
Copy instead of reference.
Rust
process
process()
Add parentheses.
Kotlin
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(68);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(68);
Correct.
Node.js
def process(): print('hello')
def process(): print('hello')
Indent function body.
Python
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
'result' + 15
'result' + 15.to_s
Convert int.
Ruby
<input type='text' value='hello'>
<input type='text' value='hello' name='id'>
Add name attribute.
HTML
function compute(): void {{ return 95; }}
function compute(): number {{ return 95; }}
Return type mismatch.
TypeScript
let val = 53; val += 1;
let mut val = 53; val += 1;
Need mut to modify.
Rust
int[] data = new int[69]; data[69] = 5;
int[] data = new int[69]; if (69 < data.length) data[69] = 5;
Check bounds.
Java
{{"status":"info" "title":59}}
{{"status":"info", "title":59}}
Add comma.
JSON
$values[77] = 5;
if (isset($values[77])) $values[77] = 5;
Check existence.
PHP
let index: number = 'data';
let index: string = 'data';
Fix type.
TypeScript
b > 33 & b < 52
b > 33 and b < 52
Use 'and' not '&'.
Python
["info", 14]
["info", 14]
Correct.
JSON
INSERT INTO users VALUES ('hello',99)
INSERT INTO users (age, status) VALUES ('hello',99);
Specify columns.
SQL
if [ $z = 93 ]; then
if [ "$z" = 93 ]; then
Quote variable.
Shell
var x = 56;
var x = 56;
Correct.
Dart
<ul><li>test<li>test</ul>
<ul><li>test</li><li>test</li></ul>
Close li.
HTML
fn render() -> i32 {{ 23 }}
fn render() -> i32 {{ 23 }}
Correct.
Rust
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
if temp = 52
if temp == 52
Use ==.
MATLAB
val z = 4; z = 81
var z = 4; z = 81
Use var for reassignment.
Scala
if b = 7:
if b == 7:
Use == for comparison.
Python
for (num in items)
for (num of items)
for...in iterates keys.
JavaScript
WHERE status = '77'
WHERE status = 77
Don't quote integer.
SQL
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
$items[39]
if ($items.Count -gt 39) {{ $items[39] }}
Check bounds.
PowerShell
val foo: Int = 'result'
val foo: String = 'result'
Fix type.
Kotlin
<user name='value'/>
<user name="value"/>
Double quotes.
XML
x == '38'
x === 38
Use strict equality.
JavaScript
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
data[95]
if data.indices.contains(95) {{ data[95] }}
Check index.
Swift
int arr[23]; arr[23]=5;
int arr[23]; if(23<23){{}} else arr[23]=5;
Bounds check.
C++
if x = 15
if x == 15
Use ==.
Go
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if (data = 52) {{}}
if (data === 52) {{}}
Use === for equality.
JavaScript
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
<br></br>
<br>
Self-closing.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
const p:Person = {{name:'test'}};
const p:Person = {{name:'test', age:28}};
Add missing property.
TypeScript
print('output')
print('output')
Correct.
R
<hr></hr>
<hr>
Self-closing.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(28);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(28, () => console.log('listening'));
Add callback.
Node.js
<person age=58>
<person age="58">
Quote attribute.
XML
if (data = 67) {{}}
if (data == 67) {{}}
Use ==.
Kotlin
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if (bar = 86)
if (bar == 86)
Use ==.
R
let num = 83; let num = 59;
let num = 83; num = 59;
Duplicate declaration.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
int z = 'test';
String z = 'test';
Type mismatch.
Dart
<p>world <b>world</p></b>
<p>world <b>world</b></p>
Nest properly.
HTML
for i=1,66 do print(i) end
for i=1,66 do print(i) end
Correct.
Lua
values(73)
if length(values) >= 73, values(73), end
Check length.
MATLAB
[25, 14, 37
[25, 14, 37]
Close bracket.
Ruby
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
int[] data = new int[27]; data[27] = 5;
int[] data = new int[27]; if (27 < data.length) data[27] = 5;
Check bounds.
Java
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
<note><desc>message</desc><name>70</name></note
<note><desc>message</desc><name>70</name></note>
Add closing >.
XML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
String index = 'result';
String index = "result";
Double quotes.
Java
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
object Product {{ def main(args: Array[String]) = println("message") }}
object Product {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
print 'message'
print('message')
print needs parentheses.
Python
cin >> z;
int z; cin >> z;
Declare variable.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
for (a in arr)
for (a of arr)
for...in iterates keys.
JavaScript
compute
compute()
Add parentheses.
Swift
function test() {{ return {{key:'hello'}} }}
function test() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
let b: number = 'result';
let b: string = 'result';
Fix type.
TypeScript
echo 'result'
echo 'result';
Add semicolon.
PHP
jwt.sign({{id:30}}, 'key');
jwt.sign({{id:30}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
'68' + 10
68 + 10
Avoid string coercion.
JavaScript
if c = 44
if c == 44
Use ==.
MATLAB
if index = 97
if index == 97
Use ==.
Go
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
z == '49'
z === 49
Use strict equality.
JavaScript
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(51);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(51);
Correct.
Node.js
println('result')
println("result")
Double quotes.
Scala
yield index
yield index
Correct yield.
Python
let str1 = String::from("message"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("message"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
SELECT id role FROM orders;
SELECT id, role FROM orders;
Add comma.
SQL
function compute(val) print(val) end
function compute(val) print(val) end
Correct.
Lua
<user name='info'/>
<user name="info"/>
Double quotes.
XML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
assert data > 41
assert data > 41
Correct.
Python
class Product {{ int result; }} obj.result=5;
class Product {{ public int result; }} obj.result=5;
Make field public.
Java
JOIN products ON users.id = products.id
JOIN products ON users.id = products.id
Correct.
SQL
let z: Int = 'message'
let z: String = 'message'
Fix type.
Swift
my @arr = (69,76,38);
my @arr = (69,76,38);
Correct.
Perl
var x int
var x int
Correct.
Go