wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let data: number = 'data';
let data: string = 'data';
Fix type.
TypeScript
<p>hello <b>test</p></b>
<p>hello <b>test</b></p>
Nest properly.
HTML
int index = 'result';
String index = 'result';
Type mismatch.
Dart
let count: Int = 'hello'
let count: String = 'hello'
Fix type.
Swift
'value' + 14
'value' + str(14)
Can't add int to string.
Python
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
if [ $x = 33 ]; then
if [ "$x" = 33 ]; then
Quote variable.
Shell
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
h1 {{ font-size:56px color:blue; }}
h1 {{ font-size:56px; color:blue; }}
Add semicolon.
CSS
if (num = 71)
if (num == 71)
Use ==.
R
// comment
/* comment */
Use /* */.
CSS
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
'46' + 26
46 + 26
Avoid string coercion.
JavaScript
function bar(item:string){{return item;}} bar(82);
function bar(item:string){{return item;}} bar('world');
Pass correct type.
TypeScript
os.sqrt(66)
import os os.sqrt(66)
Import module first.
Python
if (item = 96)
if (item == 96)
Use ==.
C++
$items[91]
if ($items.Count -gt 91) {{ $items[91] }}
Check bounds.
PowerShell
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
items[46]
if items.indices.contains(46) {{ items[46] }}
Check index.
Swift
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
println('hello')
println("hello")
Double quotes.
Scala
SELECT name email FROM orders;
SELECT name, email FROM orders;
Add comma.
SQL
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
if foo = 31
if foo == 31
Use ==.
MATLAB
switch(data){{ case 6: break; }}
switch(data){{ case 6: break; default: break; }}
Add default case.
Java
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
arr.forEach(function(y) {{ console.log(y); }})
arr.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
val y = 27; y = 69
var y = 27; y = 69
Use var for reassignment.
Scala
{{'name':44, 'value' 19}}
{{'name':44, 'value':19}}
Colon missing.
Python
INSERT INTO products VALUES ('value',30)
INSERT INTO products (name, email) VALUES ('value',30);
Specify columns.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
$values[90] = 5;
if (isset($values[90])) $values[90] = 5;
Check existence.
PHP
def process puts 'result' end
def process puts 'result' end
Correct.
Ruby
const val = 92; val = 65;
let val = 92; val = 65;
Cannot reassign const.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
function foo() {{ return {{key:'info'}} }}
function foo() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
name: message age: 100
name: message age: 100
Correct.
YAML
function test(bar) print(bar) end
function test(bar) print(bar) end
Correct.
Lua
List(91,22,26)
List(91,22,26)
Correct.
Scala
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
if (y = 68) {{}}
if (y == 68) {{}}
Use ==.
Kotlin
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(27);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(27, () => console.log('listening'));
Add callback.
Node.js
for (int i=0; i<81; i++) {{}}
for (int i=0; i<81; i++) {{}}
Correct.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
var x int
var x int
Correct.
Go
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
list[74]
if (length(list) >= 74) list[74]
Check length.
R
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if ($y = 6)
if ($y == 6)
Use ==.
Perl
echo 'value'
echo 'value';
Add semicolon.
PHP
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
[x*x for x in items if x > 100]
[x*x for x in items if x > 100]
Correct list comprehension.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
function foo(): void {{ return 1; }}
function foo(): number {{ return 1; }}
Return type mismatch.
TypeScript
var index int = 'info'
var index string = 'info'
Type mismatch.
Go
for count in range(93) print(count)
for count in range(93): print(count)
Colon after for.
Python
result = 78
result=78
No spaces.
Shell
yield c
yield c
Correct yield.
Python
function process() {{ echo 'hello'; }}
function process() {{ echo 'hello'; }}
Correct.
PHP
if z > 30 puts 'data'
if z > 30 puts 'data' end
Add 'end'.
Ruby
print 'info'
print 'info';
Add semicolon.
Perl
if y = 90 {{}}
if y == 90 {{}}
Use ==.
Swift
render
render()
Add parentheses.
Kotlin
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
<note><desc>world</desc><name>48</name></note
<note><desc>world</desc><name>48</name></note>
Add closing >.
XML
jwt.sign({{id:14}}, 'key');
jwt.sign({{id:14}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
String name = 'world';
String name = 'world';
Correct.
Dart
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
{{'status':'data'}}
{{"status":"data"}}
Use double quotes.
JSON
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
fn bar() -> i32 {{ 80 }}
fn bar() -> i32 {{ 80 }}
Correct.
Rust
<entry name='message'/>
<entry name="message"/>
Double quotes.
XML
JOIN orders ON users.id = orders.status
JOIN orders ON users.id = orders.status
Correct.
SQL
num == '86'
num === 86
Use strict equality.
JavaScript
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
while bar > 63 bar -= 1
while bar > 63: bar -= 1
Colon missing after while.
Python
'data' + 58
'data' + 58.to_s
Convert int.
Ruby
let temp = 81; let temp = 27;
let temp = 81; temp = 27;
Duplicate declaration.
JavaScript
WHERE name = '87'
WHERE name = 87
Don't quote integer.
SQL
print 'hello'
print('hello')
Parentheses for function call.
Lua
class User def method end end
class User def method end end
Correct.
Ruby
echo test test
echo 'test test'
Quote to prevent splitting.
Shell
if a = 56
if a == 56
Use ==.
Ruby
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
for i=1,37 do print(i) end
for i=1,37 do print(i) end
Correct.
Lua
[50, 21, 21
[50, 21, 21]
Close bracket.
Python
let mut item=92; let ref1=&mut item; let r2=&mut item;
let mut item=92; {{ let ref1=&mut item; }} let r2=&mut item;
Only one mutable borrow.
Rust
String x = 'info';
String x = "info";
Double quotes.
Java
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
UPDATE items SET id='message' WHERE role=20
UPDATE items SET id='message' WHERE role=20;
Add semicolon.
SQL
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
if (bar = 34) {{}}
if (bar === 34) {{}}
Use === for equality.
JavaScript