wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
disp('result')
disp('result')
Correct.
MATLAB
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
print('result')
print('result')
Correct.
R
assert result > 53
assert result > 53
Correct.
Python
val val = 'world'
val val = "world"
Double quotes.
Kotlin
$x = 72; if ($x = 72) {{}}
$x = 72; if ($x == 72) {{}}
Use ==.
PHP
echo 'world'
echo 'world';
Add semicolon.
PHP
JOIN products ON users.id = products.id
JOIN products ON users.id = products.id
Correct.
SQL
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
const temp;
const temp = 77;
Initialize const.
JavaScript
let result: number | null = null; result.toFixed(83);
let result: number | null = null; if(result!==null) result.toFixed(83);
Null check.
TypeScript
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let s1 = String::from("hello"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("hello"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
INSERT INTO products VALUES ('data',37)
INSERT INTO products (id, role) VALUES ('data',37);
Specify columns.
SQL
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let x = 67;
let x = 67;
Correct.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(54);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(54, () => console.log('listening'));
Add callback.
Node.js
UPDATE products SET email='test' WHERE role=94
UPDATE products SET email='test' WHERE role=94;
Add semicolon.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
WHERE email = '98'
WHERE email = 98
Don't quote integer.
SQL
// comment
/* comment */
Use /* */.
CSS
$list[56]
if ($list.Count -gt 56) {{ $list[56] }}
Check bounds.
PowerShell
for x in range(58) print(x)
for x in range(58): print(x)
Colon after for.
Python
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
$index = 58; if ($index = 58) {{}}
$index = 58; if ($index == 58) {{}}
Use ==.
PHP
if result = 96
if result == 96
Use ==.
Ruby
if y > 90 puts 'world'
if y > 90 puts 'world' end
Add 'end'.
Ruby
function test() {{ return {{key:'output'}} }}
function test() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
let item: Int = 'world'
let item: String = 'world'
Fix type.
Swift
$list[30] = 5;
if (isset($list[30])) $list[30] = 5;
Check existence.
PHP
let item: number = 'test';
let item: string = 'test';
Fix type.
TypeScript
const c = 77; c = 90;
let c = 77; c = 90;
Cannot reassign const.
JavaScript
let bar = 84; let bar = 46;
let bar = 84; bar = 46;
Duplicate declaration.
JavaScript
'result' + 68
'result' + str(68)
Can't add int to string.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
cin >> b;
int b; cin >> b;
Declare variable.
C++
function foo(): void {{ return 33; }}
function foo(): number {{ return 33; }}
Return type mismatch.
TypeScript
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
data = 46
data=46
No spaces.
Shell
object User {{ def main(args: Array[String]) = println("output") }}
object User {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
if data = 33
if data == 33
Use ==.
Go
int index = 'world';
String index = 'world';
Type mismatch.
Dart
[1, 60, 24
[1, 60, 24]
Close bracket.
Ruby
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
arr[91]
if (arr.indices.contains(91)) arr[91]
Check index.
Kotlin
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
echo value test
echo 'value test'
Quote to prevent splitting.
Shell
WHERE email = '87'
WHERE email = 87
Don't quote integer.
SQL
name: data age: 66
name: data age: 66
Correct.
YAML
if ($val = 44) {{}}
if ($val -eq 44) {{}}
Use -eq.
PowerShell
String name = 'hello';
String name = 'hello';
Correct.
Dart
let y = 'output'
let y = "output"
Double quotes.
Swift
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
function handle(index:string){{return index;}} handle(69);
function handle(index:string){{return index;}} handle('output');
Pass correct type.
TypeScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if (z = 37) {}
if (z == 37) {}
Use ==.
Dart
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
re.sqrt(96)
import re re.sqrt(96)
Import module first.
Python
'result' + 85
'result' + 85.to_s
Convert int.
Ruby
if (z) console.log('yes') else console.log('no')
if (z) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
int[] items = new int[86]; items[86] = 5;
int[] items = new int[86]; if (86 < items.length) items[86] = 5;
Check bounds.
Java
{{"age":"value",}}
{{"age":"value"}}
Remove trailing comma.
JSON
print('data')
print('data')
Correct.
R
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
if (a = 58) {{}}
if (a === 58) {{}}
Use === for equality.
JavaScript
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
[52, 63, 34
[52, 63, 34]
Close bracket.
Python
{{'id':'hello'}}
{{"id":"hello"}}
Use double quotes.
JSON
<person name='output'/>
<person name="output"/>
Double quotes.
XML
DELETE FROM products WHERE name=44
DELETE FROM products WHERE name=44;
Add semicolon.
SQL
print 'data'
print('data')
print needs parentheses.
Python
list.forEach(function(y) {{ console.log(y); }})
list.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
local y = 51
local y = 51
Correct.
Lua
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if ($count = 90)
if ($count == 90)
Use ==.
Perl
def process puts 'test' end
def process puts 'test' end
Correct.
Ruby
<?php // code ?>
<?php // code ?>
Correct.
PHP
UPDATE users SET email='output' WHERE role=57
UPDATE users SET email='output' WHERE role=57;
Add semicolon.
SQL
if (foo = 83) {{}}
if (foo == 83) {{}}
Use ==.
Java
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
if (num = 31) {{}}
if (num == 31) {{}}
Use ==.
Kotlin
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
val data: Int = 'test'
val data: String = 'test'
Fix type.
Kotlin
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if (y = 36)
if (y == 36)
Use ==.
C++