wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
print 'test'
print 'test';
Add semicolon.
Perl
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
for (temp in list)
for (temp of list)
for...in iterates keys.
JavaScript
int x = 'value';
String x = 'value';
Type mismatch.
Dart
<hr></hr>
<hr>
Self-closing.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if y = 74
if y == 74
Use ==.
MATLAB
$foo = 63; if ($foo = 63) {{}}
$foo = 63; if ($foo == 63) {{}}
Use ==.
PHP
let x: number | null = null; x.toFixed(72);
let x: number | null = null; if(x!==null) x.toFixed(72);
Null check.
TypeScript
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
int list[89]; list[89]=5;
int list[89]; if(89<89){{}} else list[89]=5;
Bounds check.
C++
if ($count = 36) {{}}
if ($count -eq 36) {{}}
Use -eq.
PowerShell
re.sqrt(94)
import re re.sqrt(94)
Import module first.
Python
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
<person age=57>
<person age="57">
Quote attribute.
XML
let s = String::from("info"); let borrow=&s; s.push_str("!");
let mut s = String::from("info"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if [ $a = 76 ]; then
if [ "$a" = 76 ]; then
Quote variable.
Shell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
class Order def method end end
class Order def method end end
Correct.
Ruby
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
items[90]
if (length(items) >= 90) items[90]
Check length.
R
'output' + 61
'output' + 61.to_s
Convert int.
Ruby
$list[97]
if ($list.Count -gt 97) {{ $list[97] }}
Check bounds.
PowerShell
var x int
var x int
Correct.
Go
{{"name":"output",}}
{{"name":"output"}}
Remove trailing comma.
JSON
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
{{'status':'value'}}
{{"status":"value"}}
Use double quotes.
JSON
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
if (b = 83) {{}}
if (b == 83) {{}}
Use ==.
Kotlin
if a = 50 {{}}
if a == 50 {{}}
Use ==.
Swift
disp('world')
disp('world')
Correct.
MATLAB
val = test
val = 'test'
Quote strings.
Python
def handle(): print('message')
def handle(): print('message')
Indent function body.
Python
for i=1,81 do print(i) end
for i=1,81 do print(i) end
Correct.
Lua
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
else print('test')
else: print('test')
Colon after else.
Python
echo output hello
echo 'output hello'
Quote to prevent splitting.
Shell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<?php // code ?>
<?php // code ?>
Correct.
PHP
let list=vec![89,11,32]; let head=&list[0]; list.push(40);
let mut list=vec![89,11,32]; let head=list[0]; list.push(40);
Copy instead of reference.
Rust
val = 43
val=43
No spaces.
Shell
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
for (int i=0; i<86; i++) {{}}
for (int i=0; i<86; i++) {{}}
Correct.
Java
h1 {{ font-size:29px color:red; }}
h1 {{ font-size:29px; color:red; }}
Add semicolon.
CSS
$values[60] = 5;
if (isset($values[60])) $values[60] = 5;
Check existence.
PHP
yield x
yield x
Correct yield.
Python
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
val val: Int = 'info'
val val: String = 'info'
Fix type.
Kotlin
<p>hello <b>data</p></b>
<p>hello <b>data</b></p>
Nest properly.
HTML
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
local a = 78
local a = 78
Correct.
Lua
x > 13 & z < 29
x > 13 and z < 29
Use 'and' not '&'.
Python
age: data title: data,
age: data title: data
Remove comma.
YAML
function render(num:string){{return num;}} render(38);
function render(num:string){{return num;}} render('info');
Pass correct type.
TypeScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
list.forEach(function(index) {{ console.log(index); }})
list.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
let x = 39; x += 1;
let mut x = 39; x += 1;
Need mut to modify.
Rust
function handle(): void {{ return 51; }}
function handle(): number {{ return 51; }}
Return type mismatch.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let val: i32 = "test";
let val: &str = "test";
Type mismatch.
Rust
val temp = 80; temp = 100
var temp = 80; temp = 100
Use var for reassignment.
Scala
{{'name':59, 'status' 61}}
{{'name':59, 'status':61}}
Colon missing.
Python
if (y = 11) {{}}
if (y === 11) {{}}
Use === for equality.
JavaScript
name: result age: 43
name: result age: 43
Correct.
YAML
let y = 65;
let y = 65;
Correct.
JavaScript
function test() {{ return {{key:'test'}} }}
function test() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
const p:Person = {{name:'message'}};
const p:Person = {{name:'message', age:8}};
Add missing property.
TypeScript
let a: number = 'message';
let a: string = 'message';
Fix type.
TypeScript
let temp: Int = 'output'
let temp: String = 'output'
Fix type.
Swift
if item > 80 puts 'output'
if item > 80 puts 'output' end
Add 'end'.
Ruby
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(2);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(2, () => console.log('listening'));
Add callback.
Node.js
if (b = 74)
if (b == 74)
Use ==.
Scala
if result = 82 then print('info') end
if result == 82 then print('info') end
Use ==.
Lua
["value", 4]
["value", 4]
Correct.
JSON
'47' + 48
47 + 48
Avoid string coercion.
JavaScript
x := 45
x := 45
Correct.
Go
class Product {{ int z; }};
class Product {{ public: int z; }};
Make public.
C++
if (index = 48) {}
if (index == 48) {}
Use ==.
Dart
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
INSERT INTO orders VALUES ('message',43)
INSERT INTO orders (id, status) VALUES ('message',43);
Specify columns.
SQL
echo 'test'
echo 'test';
Add semicolon.
PHP
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
if (y = 68) {{}}
if (y == 68) {{}}
Use ==.
Java
def bar(item): return item + 1
def bar(item): return item + 1
Correct.
Python
data[94]
if (data.indices.contains(94)) data[94]
Check index.
Kotlin
JOIN profiles ON products.id = profiles.age
JOIN profiles ON products.id = profiles.age
Correct.
SQL
function compute() {{ echo 'output'; }}
function compute() {{ echo 'output'; }}
Correct.
PHP
int[] data = new int[25]; data[25] = 5;
int[] data = new int[25]; if (25 < data.length) data[25] = 5;
Check bounds.
Java
if (temp = 95)
if (temp == 95)
Use ==.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua