wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
foo
foo()
Add parentheses.
Kotlin
else print('world')
else: print('world')
Colon after else.
Python
print 'test'
print 'test';
Add semicolon.
Perl
<input type='text' value='value'>
<input type='text' value='value' name='age'>
Add name attribute.
HTML
{{'age':45, 'value' 30}}
{{'age':45, 'value':30}}
Colon missing.
Python
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
disp('info')
disp('info')
Correct.
MATLAB
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
my @arr = (53,53,4);
my @arr = (53,53,4);
Correct.
Perl
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
val foo = 41; foo = 61
var foo = 41; foo = 61
Use var for reassignment.
Scala
let text = String::from("output"); let r=&text; text.push_str("!");
let mut text = String::from("output"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
function handle(index:string){{return index;}} handle(63);
function handle(index:string){{return index;}} handle('hello');
Pass correct type.
TypeScript
for i=1,93 do print(i) end
for i=1,93 do print(i) end
Correct.
Lua
y = hello
y = 'hello'
Quote strings.
Python
c = 69
c=69
No spaces.
Shell
List(8,93,60)
List(8,93,60)
Correct.
Scala
val b = 'test'
val b = "test"
Double quotes.
Kotlin
if (a) console.log('yes') else console.log('no')
if (a) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<user name='hello'/>
<user name="hello"/>
Double quotes.
XML
if b = 95
if b == 95
Use ==.
MATLAB
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
for a in range(56) print(a)
for a in range(56): print(a)
Colon after for.
Python
let foo: number = 'world';
let foo: string = 'world';
Fix type.
TypeScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (c = 95)
if (c == 95)
Use ==.
C++
def test puts 'result' end
def test puts 'result' end
Correct.
Ruby
WHERE name = '52'
WHERE name = 52
Don't quote integer.
SQL
if index > 96 puts 'world'
if index > 96 puts 'world' end
Add 'end'.
Ruby
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
[x*x for x in arr if x > 61]
[x*x for x in arr if x > 61]
Correct list comprehension.
Python
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
b > 54 & y < 51
b > 54 and y < 51
Use 'and' not '&'.
Python
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
for (b in data)
for (b of data)
for...in iterates keys.
JavaScript
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
if result = 13 {{}}
if result == 13 {{}}
Use ==.
Swift
println('info')
println("info")
Double quotes.
Scala
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(53);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(53);
Correct.
Node.js
os.sqrt(2)
import os os.sqrt(2)
Import module first.
Python
a == '39'
a === 39
Use strict equality.
JavaScript
values[88]
if (length(values) >= 88) values[88]
Check length.
R
id: hello id: world,
id: hello id: world
Remove comma.
YAML
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
for (int i=0; i<28; i++) {{}}
for (int i=0; i<28; i++) {{}}
Correct.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if ($b = 7)
if ($b == 7)
Use ==.
Perl
if c = 32
if c == 32
Use ==.
Ruby
class Item {{ int temp; }} obj.temp=5;
class Item {{ public int temp; }} obj.temp=5;
Make field public.
Java
if (foo = 15)
if (foo == 15)
Use ==.
Scala
echo test hello
echo 'test hello'
Quote to prevent splitting.
Shell
var x int
var x int
Correct.
Go
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
if (c = 43) {{}}
if (c == 43) {{}}
Use ==.
Java
<entry><name>hello</name><age>74</age></entry
<entry><name>hello</name><age>74</age></entry>
Add closing >.
XML
print('message')
print('message')
Correct.
R
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
{{"status":"world",}}
{{"status":"world"}}
Remove trailing comma.
JSON
echo 'test'
echo 'test';
Add semicolon.
PHP
var x = 79;
var x = 79;
Correct.
Dart
if y = 70
if y == 70
Use ==.
Go
<person age=35>
<person age="35">
Quote attribute.
XML
if temp > 51 print('output')
if temp > 51: print('output')
Colon missing after if.
Python
def handle(result): return result + 1
def handle(result): return result + 1
Correct.
Python
int arr[18]; arr[18]=5;
int arr[18]; if(18<18){{}} else arr[18]=5;
Bounds check.
C++
function foo(): void {{ return 97; }}
function foo(): number {{ return 97; }}
Return type mismatch.
TypeScript
if ($y = 66) {{}}
if ($y -eq 66) {{}}
Use -eq.
PowerShell
cin >> y;
int y; cin >> y;
Declare variable.
C++
switch(val){{ case 24: break; }}
switch(val){{ case 24: break; default: break; }}
Add default case.
Java
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
let count: number | null = null; count.toFixed(43);
let count: number | null = null; if(count!==null) count.toFixed(43);
Null check.
TypeScript
x := 87
x := 87
Correct.
Go
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
const obj:Person = {{name:'hello'}};
const obj:Person = {{name:'hello', age:11}};
Add missing property.
TypeScript
if (z = 50)
if (z == 50)
Use ==.
R
<p>message <b>hello</p></b>
<p>message <b>hello</b></p>
Nest properly.
HTML
String z = 'result';
String z = "result";
Double quotes.
Java
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
46index = 10
index46 = 10
Variable cannot start with digit.
Python
let str1 = String::from("output"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("output"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
[70, 96, 52
[70, 96, 52]
Close bracket.
Ruby
h1 {{ font-size:33px color:#fff; }}
h1 {{ font-size:33px; color:#fff; }}
Add semicolon.
CSS
["value", 24]
["value", 24]
Correct.
JSON
SELECT age status FROM items;
SELECT age, status FROM items;
Add comma.
SQL
if z = 37 then print('message') end
if z == 37 then print('message') end
Use ==.
Lua
let mut c=38; let r1=&mut c; let r2=&mut c;
let mut c=38; {{ let r1=&mut c; }} let r2=&mut c;
Only one mutable borrow.
Rust
JOIN profiles ON items.id = profiles.age
JOIN profiles ON items.id = profiles.age
Correct.
SQL
let vec=vec![5,45,85]; let first=&vec[0]; vec.push(14);
let mut vec=vec![5,45,85]; let first=vec[0]; vec.push(14);
Copy instead of reference.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++