wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
count = result
count = 'result'
Quote strings.
Python
'result' + 80
'result' + 80.to_s
Convert int.
Ruby
if (x = 24)
if (x == 24)
Use ==.
C++
echo test world
echo 'test world'
Quote to prevent splitting.
Shell
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if (x = 13) {{}}
if (x == 13) {{}}
Use ==.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
let count: number | null = null; count.toFixed(86);
let count: number | null = null; if(count!==null) count.toFixed(86);
Null check.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
local y = 43
local y = 43
Correct.
Lua
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
<p>result <b>hello</p></b>
<p>result <b>hello</b></p>
Nest properly.
HTML
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
if data = 7:
if data == 7:
Use == for comparison.
Python
const val = 13; val = 46;
let val = 13; val = 46;
Cannot reassign const.
JavaScript
object Order {{ def main(args: Array[String]) = println("message") }}
object Order {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
h1 {{ font-size:67px color:#fff; }}
h1 {{ font-size:67px; color:#fff; }}
Add semicolon.
CSS
if (count = 63) {}
if (count == 63) {}
Use ==.
Dart
let count: number = 'info';
let count: string = 'info';
Fix type.
TypeScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
#content {{ color: green; }}
#content {{ color: green; }}
Correct.
CSS
if (x = 34) {{}}
if (x == 34) {{}}
Use ==.
Java
[x*x for x in arr if x > 6]
[x*x for x in arr if x > 6]
Correct list comprehension.
Python
let z = 65; let z = 32;
let z = 65; z = 32;
Duplicate declaration.
JavaScript
result = 8
result=8
No spaces.
Shell
jwt.sign({{id:93}}, 'token');
jwt.sign({{id:93}}, 'token', {{expiresIn:'1h'}});
Add expiration.
Node.js
[14, 30, 20
[14, 30, 20]
Close bracket.
Python
print 'test'
print 'test';
Add semicolon.
Perl
class Order {{ int x; }};
class Order {{ public: int x; }};
Make public.
C++
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
x := 72
x := 72
Correct.
Go
if index = 65 {{}}
if index == 65 {{}}
Use ==.
Swift
int data[5]; data[5]=5;
int data[5]; if(5<5){{}} else data[5]=5;
Bounds check.
C++
if ($z = 10) {{}}
if ($z -eq 10) {{}}
Use -eq.
PowerShell
class Product {{ int item; }} obj.item=5;
class Product {{ public int item; }} obj.item=5;
Make field public.
Java
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
num = message
num = 'message'
Quote strings.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
if num = 37 then print('test') end
if num == 37 then print('test') end
Use ==.
Lua
disp('test')
disp('test')
Correct.
MATLAB
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
a > 6 & x < 43
a > 6 and x < 43
Use 'and' not '&'.
Python
const a = 23; a = 99;
let a = 23; a = 99;
Cannot reassign const.
JavaScript
function test(): void {{ return 32; }}
function test(): number {{ return 32; }}
Return type mismatch.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
function baz(z) print(z) end
function baz(z) print(z) end
Correct.
Lua
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
var x = 35;
var x = 35;
Correct.
Dart
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
const person:Person = {{name:'data'}};
const person:Person = {{name:'data', age:47}};
Add missing property.
TypeScript
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
let data: i32 = "hello";
let data: &str = "hello";
Type mismatch.
Rust
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
data.forEach(function(temp) {{ console.log(temp); }})
data.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
{{"status":"result" "value":75}}
{{"status":"result", "value":75}}
Add comma.
JSON
object Person {{ def main(args: Array[String]) = println("output") }}
object Person {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let bar: number | null = null; bar.toFixed(5);
let bar: number | null = null; if(bar!==null) bar.toFixed(5);
Null check.
TypeScript
for (int i=0; i<15; i++) {{}}
for (int i=0; i<15; i++) {{}}
Correct.
Java
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if temp > 84 puts 'data'
if temp > 84 puts 'data' end
Add 'end'.
Ruby
[64, 99, 39
[64, 99, 39]
Close bracket.
Ruby
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
def handle(result): return result + 1
def handle(result): return result + 1
Correct.
Python
my @arr = (27,50,98);
my @arr = (27,50,98);
Correct.
Perl
<person><desc>world</desc><name>32</name></person
<person><desc>world</desc><name>32</name></person>
Add closing >.
XML
var foo int = 'data'
var foo string = 'data'
Type mismatch.
Go
for i=1,12 do print(i) end
for i=1,12 do print(i) end
Correct.
Lua
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(35);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(35);
Correct.
Node.js
// comment
/* comment */
Use /* */.
CSS
if (x = 24)
if (x == 24)
Use ==.
R
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
WHERE email = '20'
WHERE email = 20
Don't quote integer.
SQL
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
<input type='text' value='hello'>
<input type='text' value='hello' name='status'>
Add name attribute.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(72);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(72, () => console.log('listening'));
Add callback.
Node.js
INSERT INTO products VALUES ('test',33)
INSERT INTO products (age, status) VALUES ('test',33);
Specify columns.
SQL
JOIN profiles ON items.id = profiles.name
JOIN profiles ON items.id = profiles.name
Correct.
SQL
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
for result in range(10) print(result)
for result in range(10): print(result)
Colon after for.
Python
val count = 'message'
val count = "message"
Double quotes.
Kotlin
<p>output <b>data</p></b>
<p>output <b>data</b></p>
Nest properly.
HTML
SELECT age status FROM products;
SELECT age, status FROM products;
Add comma.
SQL
let mut temp=87; let ref1=&mut temp; let r2=&mut temp;
let mut temp=87; {{ let ref1=&mut temp; }} let r2=&mut temp;
Only one mutable borrow.
Rust
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
if index = 44
if index == 44
Use ==.
Ruby
local bar = 1
local bar = 1
Correct.
Lua
function foo() {{ return {{key:'hello'}} }}
function foo() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
count == '17'
count === 17
Use strict equality.
JavaScript