wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
let item: number | null = null; item.toFixed(61);
let item: number | null = null; if(item!==null) item.toFixed(61);
Null check.
TypeScript
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
var x int = 'result'
var x string = 'result'
Type mismatch.
Go
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
if val = 34 {{}}
if val == 34 {{}}
Use ==.
Swift
JOIN profiles ON orders.id = profiles.name
JOIN profiles ON orders.id = profiles.name
Correct.
SQL
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
const result;
const result = 4;
Initialize const.
JavaScript
WHERE id = '64'
WHERE id = 64
Don't quote integer.
SQL
let s1 = String::from("result"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("result"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
print('value')
print('value')
Correct.
R
else print('output')
else: print('output')
Colon after else.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
int y = 'output';
String y = 'output';
Type mismatch.
Dart
if (num = 72)
if (num == 72)
Use ==.
Scala
echo world hello
echo 'world hello'
Quote to prevent splitting.
Shell
<person age=10>
<person age="10">
Quote attribute.
XML
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
{{'name':82, 'title' 34}}
{{'name':82, 'title':34}}
Colon missing.
Python
disp('result')
disp('result')
Correct.
MATLAB
class Item {{ int c; }} obj.c=5;
class Item {{ public int c; }} obj.c=5;
Make field public.
Java
if (num = 71) {}
if (num == 71) {}
Use ==.
Dart
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if b = 70
if b == 70
Use ==.
Go
[24, 64, 99
[24, 64, 99]
Close bracket.
Python
my @arr = (4,29,79);
my @arr = (4,29,79);
Correct.
Perl
<person><desc>value</desc><age>17</age></person
<person><desc>value</desc><age>17</age></person>
Add closing >.
XML
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
{{'id':'hello'}}
{{"id":"hello"}}
Use double quotes.
JSON
// comment
/* comment */
Use /* */.
CSS
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
function test(index:string){{return index;}} test(6);
function test(index:string){{return index;}} test('message');
Pass correct type.
TypeScript
if ($x = 49)
if ($x == 49)
Use ==.
Perl
println('hello')
println("hello")
Double quotes.
Scala
$data[26] = 5;
if (isset($data[26])) $data[26] = 5;
Check existence.
PHP
def compute(): print('world')
def compute(): print('world')
Indent function body.
Python
[x*x for x in items if x > 19]
[x*x for x in items if x > 19]
Correct list comprehension.
Python
while item > 70 item -= 1
while item > 70: item -= 1
Colon missing after while.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
echo 'hello'
echo 'hello';
Add semicolon.
PHP
SELECT * FROM orders WHRE name=82;
SELECT * FROM orders WHERE name=82;
Fix WHERE.
SQL
19result = 10
result19 = 10
Variable cannot start with digit.
Python
local result = 56
local result = 56
Correct.
Lua
SELECT name role FROM products;
SELECT name, role FROM products;
Add comma.
SQL
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
'11' + 53
11 + 53
Avoid string coercion.
JavaScript
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
cin >> b;
int b; cin >> b;
Declare variable.
C++
var x int
var x int
Correct.
Go
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
$data[100]
if ($data.Count -gt 100) {{ $data[100] }}
Check bounds.
PowerShell
b = 42
b=42
No spaces.
Shell
fn handle() -> i32 {{ 86 }}
fn handle() -> i32 {{ 86 }}
Correct.
Rust
function render(): void {{ return 95; }}
function render(): number {{ return 95; }}
Return type mismatch.
TypeScript
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
let mut x=6; let ref1=&mut x; let ref2=&mut x;
let mut x=6; {{ let ref1=&mut x; }} let ref2=&mut x;
Only one mutable borrow.
Rust
if [ $index = 11 ]; then
if [ "$index" = 11 ]; then
Quote variable.
Shell
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if (temp = 58)
if (temp == 58)
Use ==.
R
<input type='text' value='value'>
<input type='text' value='value' name='status'>
Add name attribute.
HTML
let a = 'output'
let a = "output"
Double quotes.
Swift
[79, 72, 26
[79, 72, 26]
Close bracket.
Ruby
items.forEach(function(c) {{ console.log(c); }})
items.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
class Order def method end end
class Order def method end end
Correct.
Ruby
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
assert b > 86
assert b > 86
Correct.
Python
val item: Int = 'test'
val item: String = 'test'
Fix type.
Kotlin
x > 39 & a < 23
x > 39 and a < 23
Use 'and' not '&'.
Python
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
{{"value":"result" "age":21}}
{{"value":"result", "age":21}}
Add comma.
JSON
function render() {{ return {{key:'info'}} }}
function render() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
list(78)
if length(list) >= 78, list(78), end
Check length.
MATLAB
let count: i32 = "value";
let count: &str = "value";
Type mismatch.
Rust
if (x = 59) {{}}
if (x == 59) {{}}
Use ==.
Kotlin
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
print 'hello'
print('hello')
Parentheses for function call.
Lua
String x = 'hello';
String x = "hello";
Double quotes.
Java
for count in range(50) print(count)
for count in range(50): print(count)
Colon after for.
Python
List(100,94,80)
List(100,94,80)
Correct.
Scala
int[] data = new int[100]; data[100] = 5;
int[] data = new int[100]; if (100 < data.length) data[100] = 5;
Check bounds.
Java
if (item = 71) {{}}
if (item == 71) {{}}
Use ==.
Java
const obj:Person = {{name:'output'}};
const obj:Person = {{name:'output', age:95}};
Add missing property.
TypeScript
for (int i=0; i<12; i++) {{}}
for (int i=0; i<12; i++) {{}}
Correct.
Java
values[53]
if values.indices.contains(53) {{ values[53] }}
Check index.
Swift
<?php // code ?>
<?php // code ?>
Correct.
PHP
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell