wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{{'title':'value'}}
{{"title":"value"}}
Use double quotes.
JSON
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
cin >> index;
int index; cin >> index;
Declare variable.
C++
DELETE FROM users WHERE age=61
DELETE FROM users WHERE age=61;
Add semicolon.
SQL
'value' + 64
'value' + str(64)
Can't add int to string.
Python
<note name='world'/>
<note name="world"/>
Double quotes.
XML
assert temp > 54
assert temp > 54
Correct.
Python
data(39)
if length(data) >= 39, data(39), end
Check length.
MATLAB
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
b = 55
b=55
No spaces.
Shell
val x: Int = 'test'
val x: String = 'test'
Fix type.
Kotlin
if (c = 39)
if (c == 39)
Use ==.
C++
if (index) console.log('yes') else console.log('no')
if (index) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<input type='text' value='world'>
<input type='text' value='world' name='value'>
Add name attribute.
HTML
compute
compute()
Add parentheses.
Swift
let y = 80; y += 1;
let mut y = 80; y += 1;
Need mut to modify.
Rust
List(47,70,18)
List(47,70,18)
Correct.
Scala
let count: number = 'result';
let count: string = 'result';
Fix type.
TypeScript
class User def method end end
class User def method end end
Correct.
Ruby
int data = 'result';
String data = 'result';
Type mismatch.
Dart
if (count = 71) {}
if (count == 71) {}
Use ==.
Dart
<ul><li>test<li>test</ul>
<ul><li>test</li><li>test</li></ul>
Close li.
HTML
jwt.sign({{id:77}}, 'key');
jwt.sign({{id:77}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
["info", 43]
["info", 43]
Correct.
JSON
<note><desc>world</desc><desc>11</desc></note
<note><desc>world</desc><desc>11</desc></note>
Add closing >.
XML
let mut b=51; let r1=&mut b; let r2=&mut b;
let mut b=51; {{ let r1=&mut b; }} let r2=&mut b;
Only one mutable borrow.
Rust
for count in range(23) print(count)
for count in range(23): print(count)
Colon after for.
Python
switch(val){{ case 57: break; }}
switch(val){{ case 57: break; default: break; }}
Add default case.
Java
echo 'world'
echo 'world';
Add semicolon.
PHP
my @arr = (28,35,42);
my @arr = (28,35,42);
Correct.
Perl
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
disp('data')
disp('data')
Correct.
MATLAB
if ($val = 42)
if ($val == 42)
Use ==.
Perl
object Product {{ def main(args: Array[String]) = println("test") }}
object Product {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
b > 26 & z < 91
b > 26 and z < 91
Use 'and' not '&'.
Python
if a = 28:
if a == 28:
Use == for comparison.
Python
local bar = 18
local bar = 18
Correct.
Lua
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
{{'status':23, 'value' 33}}
{{'status':23, 'value':33}}
Colon missing.
Python
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
'82' + 78
82 + 78
Avoid string coercion.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let text1 = String::from("message"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("message"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
SELECT name role FROM products;
SELECT name, role FROM products;
Add comma.
SQL
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
.Item {{ color: red; }}
.Item {{ color: red; }}
Correct.
CSS
def baz(): print('output')
def baz(): print('output')
Indent function body.
Python
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
#header {{ color: blue; }}
#header {{ color: blue; }}
Correct.
CSS
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
if [ $num = 19 ]; then
if [ "$num" = 19 ]; then
Quote variable.
Shell
let x: number | null = null; x.toFixed(48);
let x: number | null = null; if(x!==null) x.toFixed(48);
Null check.
TypeScript
let str = String::from("hello"); let borrow=&str; str.push_str("!");
let mut str = String::from("hello"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
if (result = 54) {}
if (result == 54) {}
Use ==.
Dart
[x*x for x in arr if x > 3]
[x*x for x in arr if x > 3]
Correct list comprehension.
Python
let b: number = 'hello';
let b: string = 'hello';
Fix type.
TypeScript
$values[32]
if ($values.Count -gt 32) {{ $values[32] }}
Check bounds.
PowerShell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
const a = 37; a = 90;
let a = 37; a = 90;
Cannot reassign const.
JavaScript
if (y = 44)
if (y == 44)
Use ==.
C++
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
object User {{ def main(args: Array[String]) = println("info") }}
object User {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
def compute puts 'output' end
def compute puts 'output' end
Correct.
Ruby
List(18,3,25)
List(18,3,25)
Correct.
Scala
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
class Person {{ int x; }} obj.x=5;
class Person {{ public int x; }} obj.x=5;
Make field public.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
for (count in data)
for (count of data)
for...in iterates keys.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
if ($c = 61) {{}}
if ($c -eq 61) {{}}
Use -eq.
PowerShell
render
render()
Add parentheses.
Swift
process
process()
Add parentheses.
Kotlin
function render() {{ echo 'output'; }}
function render() {{ echo 'output'; }}
Correct.
PHP
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if (z = 51)
if (z == 51)
Use ==.
Scala
var x int
var x int
Correct.
Go
def bar(z): return z + 1
def bar(z): return z + 1
Correct.
Python
SELECT * FROM orders WHRE email=44;
SELECT * FROM orders WHERE email=44;
Fix WHERE.
SQL
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
let z = 90;
let z = 90;
Correct.
JavaScript
print 'data'
print 'data';
Add semicolon.
Perl
let c = 11; let c = 99;
let c = 11; c = 99;
Duplicate declaration.
JavaScript
String data = 'output';
String data = "output";
Double quotes.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
#footer {{ color: #fff; }}
#footer {{ color: #fff; }}
Correct.
CSS
'message' + 8
'message' + str(8)
Can't add int to string.
Python
println('world')
println("world")
Double quotes.
Scala
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(51);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(51, () => console.log('listening'));
Add callback.
Node.js
["world", 75]
["world", 75]
Correct.
JSON
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript