wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
x > 28 & y < 91
x > 28 and y < 91
Use 'and' not '&'.
Python
my @arr = (63,50,78);
my @arr = (63,50,78);
Correct.
Perl
SELECT * FROM users WHRE id=43;
SELECT * FROM users WHERE id=43;
Fix WHERE.
SQL
let temp: number | null = null; temp.toFixed(45);
let temp: number | null = null; if(temp!==null) temp.toFixed(45);
Null check.
TypeScript
<person age=95>
<person age="95">
Quote attribute.
XML
JOIN profiles ON items.id = profiles.id
JOIN profiles ON items.id = profiles.id
Correct.
SQL
{{'id':'info'}}
{{"id":"info"}}
Use double quotes.
JSON
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
INSERT INTO items VALUES ('test',74)
INSERT INTO items (name, role) VALUES ('test',74);
Specify columns.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(52);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(52, () => console.log('listening'));
Add callback.
Node.js
[x*x for x in arr if x > 97]
[x*x for x in arr if x > 97]
Correct list comprehension.
Python
let item = 'value'
let item = "value"
Double quotes.
Swift
cin >> item cout << item;
cin >> item; cout << item;
Add semicolon.
C++
function handle() {{ return {{key:'hello'}} }}
function handle() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
if [ $num = 26 ]; then
if [ "$num" = 26 ]; then
Quote variable.
Shell
{{"name":"info",}}
{{"name":"info"}}
Remove trailing comma.
JSON
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
items(35)
if length(items) >= 35, items(35), end
Check length.
MATLAB
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
process
process()
Add parentheses.
Kotlin
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
status: hello status: world,
status: hello status: world
Remove comma.
YAML
if b > 67 print('output')
if b > 67: print('output')
Colon missing after if.
Python
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
def foo(b): return b + 1
def foo(b): return b + 1
Correct.
Python
let bar: i32 = "result";
let bar: &str = "result";
Type mismatch.
Rust
if ($item = 74)
if ($item == 74)
Use ==.
Perl
bar
bar()
Add parentheses.
Swift
<?php // code ?>
<?php // code ?>
Correct.
PHP
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
yield temp
yield temp
Correct yield.
Python
disp('hello')
disp('hello')
Correct.
MATLAB
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
String name = 'value';
String name = 'value';
Correct.
Dart
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
for i=1,16 do print(i) end
for i=1,16 do print(i) end
Correct.
Lua
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
function process(result) print(result) end
function process(result) print(result) end
Correct.
Lua
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
if x > 58 puts 'info'
if x > 58 puts 'info' end
Add 'end'.
Ruby
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
echo 'result'
echo 'result';
Add semicolon.
PHP
SELECT id email FROM orders;
SELECT id, email FROM orders;
Add comma.
SQL
let mut result=1; let r1=&mut result; let ref2=&mut result;
let mut result=1; {{ let r1=&mut result; }} let ref2=&mut result;
Only one mutable borrow.
Rust
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
val data = 63; data = 14
var data = 63; data = 14
Use var for reassignment.
Scala
if (z = 49) {{}}
if (z == 49) {{}}
Use ==.
Kotlin
name: world age: 65
name: world age: 65
Correct.
YAML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if num = 4:
if num == 4:
Use == for comparison.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let bar = 30; bar += 1;
let mut bar = 30; bar += 1;
Need mut to modify.
Rust
if (item = 65) {}
if (item == 65) {}
Use ==.
Dart
item == '19'
item === 19
Use strict equality.
JavaScript
function foo(temp:string){{return temp;}} foo(46);
function foo(temp:string){{return temp;}} foo('message');
Pass correct type.
TypeScript
let str1 = String::from("value"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("value"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
os.sqrt(86)
import os os.sqrt(86)
Import module first.
Python
int data[22]; data[22]=5;
int data[22]; if(22<22){{}} else data[22]=5;
Bounds check.
C++
if ($z = 82) {{}}
if ($z -eq 82) {{}}
Use -eq.
PowerShell
'31' + 100
31 + 100
Avoid string coercion.
JavaScript
int[] data = new int[70]; data[70] = 5;
int[] data = new int[70]; if (70 < data.length) data[70] = 5;
Check bounds.
Java
["message", 67]
["message", 67]
Correct.
JSON
<hr></hr>
<hr>
Self-closing.
HTML
int result = 'result';
String result = 'result';
Type mismatch.
Dart
print('world')
print('world')
Correct.
R
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
class User {{ int item; }} obj.item=5;
class User {{ public int item; }} obj.item=5;
Make field public.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if (item = 20)
if (item == 20)
Use ==.
C++
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
for (int i=0; i<15; i++) {{}}
for (int i=0; i<15; i++) {{}}
Correct.
Java
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
val item: Int = 'test'
val item: String = 'test'
Fix type.
Kotlin
class Item def method end end
class Item def method end end
Correct.
Ruby
<user name='hello'/>
<user name="hello"/>
Double quotes.
XML
let text = String::from("result"); let borrow=&text; text.push_str("!");
let mut text = String::from("result"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
x := 96
x := 96
Correct.
Go
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
println('hello')
println("hello")
Double quotes.
Scala
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
const count = 64; count = 21;
let count = 64; count = 21;
Cannot reassign const.
JavaScript
.User {{ color: blue; }}
.User {{ color: blue; }}
Correct.
CSS
if y = 58
if y == 58
Use ==.
MATLAB
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
const p:Person = {{name:'result'}};
const p:Person = {{name:'result', age:5}};
Add missing property.
TypeScript
<br></br>
<br>
Self-closing.
HTML
object User {{ def main(args: Array[String]) = println("test") }}
object User {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
const x;
const x = 98;
Initialize const.
JavaScript