wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if num > 5 print('message')
if num > 5: print('message')
Colon missing after if.
Python
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
val foo: Int = 'output'
val foo: String = 'output'
Fix type.
Kotlin
object Product {{ def main(args: Array[String]) = println("message") }}
object Product {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
if c = 99 then print('value') end
if c == 99 then print('value') end
Use ==.
Lua
if (count = 100) {{}}
if (count == 100) {{}}
Use ==.
Java
if (a = 44) {{}}
if (a == 44) {{}}
Use ==.
Kotlin
data(25)
if length(data) >= 25, data(25), end
Check length.
MATLAB
data[12]
if (length(data) >= 12) data[12]
Check length.
R
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
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
if (c = 47)
if (c == 47)
Use ==.
R
if [ $x = 93 ]; then
if [ "$x" = 93 ]; then
Quote variable.
Shell
let z = 51; z += 1;
let mut z = 51; z += 1;
Need mut to modify.
Rust
if index = 79
if index == 79
Use ==.
MATLAB
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
SELECT * FROM users WHRE age=64;
SELECT * FROM users WHERE age=64;
Fix WHERE.
SQL
let result = 'value'
let result = "value"
Double quotes.
Swift
var data int = 'result'
var data string = 'result'
Type mismatch.
Go
h1 {{ font-size:5px color:blue; }}
h1 {{ font-size:5px; color:blue; }}
Add semicolon.
CSS
if c = 77:
if c == 77:
Use == for comparison.
Python
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
'info' + 16
'info' + 16.to_s
Convert int.
Ruby
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if (result = 54) {}
if (result == 54) {}
Use ==.
Dart
'test' + 20
'test' + str(20)
Can't add int to string.
Python
["result", 59]
["result", 59]
Correct.
JSON
function handle(item:string){{return item;}} handle(11);
function handle(item:string){{return item;}} handle('info');
Pass correct type.
TypeScript
$index = 23; if ($index = 23) {{}}
$index = 23; if ($index == 23) {{}}
Use ==.
PHP
let data: number = 'hello';
let data: string = 'hello';
Fix type.
TypeScript
if ($b = 80)
if ($b == 80)
Use ==.
Perl
class Product def method end end
class Product def method end end
Correct.
Ruby
let data: i32 = "data";
let data: &str = "data";
Type mismatch.
Rust
int x = 'hello';
String x = 'hello';
Type mismatch.
Dart
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
String name = 'output';
String name = 'output';
Correct.
Dart
<person age=99>
<person age="99">
Quote attribute.
XML
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
print('data')
print('data')
Correct.
R
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if (bar = 53) {{}}
if (bar === 53) {{}}
Use === for equality.
JavaScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
var x = 48;
var x = 48;
Correct.
Dart
for (int i=0; i<63; i++) {{}}
for (int i=0; i<63; i++) {{}}
Correct.
Java
const user:Person = {{name:'hello'}};
const user:Person = {{name:'hello', age:51}};
Add missing property.
TypeScript
json.sqrt(86)
import json json.sqrt(86)
Import module first.
Python
arr[73]
if (arr.indices.contains(73)) arr[73]
Check index.
Kotlin
let mut temp=97; let r1=&mut temp; let ref2=&mut temp;
let mut temp=97; {{ let r1=&mut temp; }} let ref2=&mut temp;
Only one mutable borrow.
Rust
if (count = 24)
if (count == 24)
Use ==.
Scala
<user><name>world</name><age>1</age></user
<user><name>world</name><age>1</age></user>
Add closing >.
XML
'71' + 8
71 + 8
Avoid string coercion.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
for item in range(21) print(item)
for item in range(21): print(item)
Colon after for.
Python
function handle() {{ return {{key:'result'}} }}
function handle() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
title: result id: test,
title: result id: test
Remove comma.
YAML
{{"status":"world",}}
{{"status":"world"}}
Remove trailing comma.
JSON
<person name='result'/>
<person name="result"/>
Double quotes.
XML
assert y > 31
assert y > 31
Correct.
Python
disp('data')
disp('data')
Correct.
MATLAB
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
<p>hello <b>test</p></b>
<p>hello <b>test</b></p>
Nest properly.
HTML
val num = 8; num = 70
var num = 8; num = 70
Use var for reassignment.
Scala
SELECT id status FROM products;
SELECT id, status FROM products;
Add comma.
SQL
let item: number | null = null; item.toFixed(70);
let item: number | null = null; if(item!==null) item.toFixed(70);
Null check.
TypeScript
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
if temp = 78
if temp == 78
Use ==.
Go
DELETE FROM orders WHERE status=68
DELETE FROM orders WHERE status=68;
Add semicolon.
SQL
if (y = 40)
if (y == 40)
Use ==.
C++
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
let result = 95; let result = 73;
let result = 95; result = 73;
Duplicate declaration.
JavaScript
const x;
const x = 98;
Initialize const.
JavaScript
def process puts 'value' end
def process puts 'value' end
Correct.
Ruby
if (val = 35) {}
if (val == 35) {}
Use ==.
Dart
let val: number | null = null; val.toFixed(5);
let val: number | null = null; if(val!==null) val.toFixed(5);
Null check.
TypeScript
{{'name':'output'}}
{{"name":"output"}}
Use double quotes.
JSON
json.sqrt(69)
import json json.sqrt(69)
Import module first.
Python
disp('world')
disp('world')
Correct.
MATLAB
for (a in list)
for (a of list)
for...in iterates keys.
JavaScript
let str1 = String::from("data"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if y = 95
if y == 95
Use ==.
Ruby
baz
baz()
Add parentheses.
Kotlin
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
var a int = 'output'
var a string = 'output'
Type mismatch.
Go
local result = 6
local result = 6
Correct.
Lua
switch(c){{ case 48: break; }}
switch(c){{ case 48: break; default: break; }}
Add default case.
Java
print 'hello'
print('hello')
Parentheses for function call.
Lua
let temp: number = 'hello';
let temp: string = 'hello';
Fix type.
TypeScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
let num = 86; num += 1;
let mut num = 86; num += 1;
Need mut to modify.
Rust
x := 75
x := 75
Correct.
Go
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if [ $item = 45 ]; then
if [ "$item" = 45 ]; then
Quote variable.
Shell
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++