wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let z: number | null = null; z.toFixed(91);
let z: number | null = null; if(z!==null) z.toFixed(91);
Null check.
TypeScript
if (temp = 13) {{}}
if (temp === 13) {{}}
Use === for equality.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
'44' + 4
44 + 4
Avoid string coercion.
JavaScript
["message", 62]
["message", 62]
Correct.
JSON
[27, 91, 27
[27, 91, 27]
Close bracket.
Ruby
if ($x = 51)
if ($x == 51)
Use ==.
Perl
int arr[77]; arr[77]=5;
int arr[77]; if(77<77){{}} else arr[77]=5;
Bounds check.
C++
const c;
const c = 51;
Initialize const.
JavaScript
<entry><name>world</name><name>47</name></entry
<entry><name>world</name><name>47</name></entry>
Add closing >.
XML
arr[66]
if (arr.indices.contains(66)) arr[66]
Check index.
Kotlin
INSERT INTO orders VALUES ('value',19)
INSERT INTO orders (id, email) VALUES ('value',19);
Specify columns.
SQL
items[71]
if items.indices.contains(71) {{ items[71] }}
Check index.
Swift
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
List(73,25,98)
List(73,25,98)
Correct.
Scala
local foo = 58
local foo = 58
Correct.
Lua
let foo = 29;
let foo = 29;
Correct.
JavaScript
y == '38'
y === 38
Use strict equality.
JavaScript
a > 31 & b < 44
a > 31 and b < 44
Use 'and' not '&'.
Python
if (z = 2) {{}}
if (z === 2) {{}}
Use === for equality.
JavaScript
bar
bar()
Add parentheses.
Kotlin
function baz(): void {{ return 44; }}
function baz(): number {{ return 44; }}
Return type mismatch.
TypeScript
1c = 10
c1 = 10
Variable cannot start with digit.
Python
<p>world <b>world</p></b>
<p>world <b>world</b></p>
Nest properly.
HTML
if (temp = 99) {}
if (temp == 99) {}
Use ==.
Dart
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
{{"name":"info",}}
{{"name":"info"}}
Remove trailing comma.
JSON
{{'age':'result'}}
{{"age":"result"}}
Use double quotes.
JSON
if ($num = 82) {{}}
if ($num -eq 82) {{}}
Use -eq.
PowerShell
for bar in range(54) print(bar)
for bar in range(54): print(bar)
Colon after for.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
let mut num=6; let r1=&mut num; let ref2=&mut num;
let mut num=6; {{ let r1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
x := 44
x := 44
Correct.
Go
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
val z = 78; z = 84
var z = 78; z = 84
Use var for reassignment.
Scala
name: world age: 66
name: world age: 66
Correct.
YAML
if (result = 53) {{}}
if (result == 53) {{}}
Use ==.
Kotlin
if item > 38 puts 'info'
if item > 38 puts 'info' end
Add 'end'.
Ruby
index = 67
index=67
No spaces.
Shell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if (b = 41)
if (b == 41)
Use ==.
R
if a = 2 {{}}
if a == 2 {{}}
Use ==.
Swift
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
const a = 32; a = 43;
let a = 32; a = 43;
Cannot reassign const.
JavaScript
let y: number | null = null; y.toFixed(42);
let y: number | null = null; if(y!==null) y.toFixed(42);
Null check.
TypeScript
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
var num int = 'result'
var num string = 'result'
Type mismatch.
Go
if (x = 63)
if (x == 63)
Use ==.
C++
if [ $foo = 86 ]; then
if [ "$foo" = 86 ]; then
Quote variable.
Shell
if temp = 38:
if temp == 38:
Use == for comparison.
Python
if (index) console.log('yes') else console.log('no')
if (index) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
assert foo > 48
assert foo > 48
Correct.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
def foo puts 'data' end
def foo puts 'data' end
Correct.
Ruby
function bar(data) print(data) end
function bar(data) print(data) end
Correct.
Lua
println('result')
println("result")
Double quotes.
Scala
class Product {{ int index; }};
class Product {{ public: int index; }};
Make public.
C++
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
title: output id: hello,
title: output id: hello
Remove comma.
YAML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
item = world
item = 'world'
Quote strings.
Python
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<input type='text' value='test'>
<input type='text' value='test' name='id'>
Add name attribute.
HTML
let num = 'message'
let num = "message"
Double quotes.
Swift
$arr[91]
if ($arr.Count -gt 91) {{ $arr[91] }}
Check bounds.
PowerShell
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
let b: Int = 'test'
let b: String = 'test'
Fix type.
Swift
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for (int i=0; i<79; i++) {{}}
for (int i=0; i<79; i++) {{}}
Correct.
Java
<br></br>
<br>
Self-closing.
HTML
my @arr = (48,37,5);
my @arr = (48,37,5);
Correct.
Perl
String b = 'hello';
String b = "hello";
Double quotes.
Java
let x: number = 'output';
let x: string = 'output';
Fix type.
TypeScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
print 'message'
print 'message';
Add semicolon.
Perl
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
val z: Int = 'output'
val z: String = 'output'
Fix type.
Kotlin
UPDATE users SET id='hello' WHERE status=77
UPDATE users SET id='hello' WHERE status=77;
Add semicolon.
SQL
val b = 'world'
val b = "world"
Double quotes.
Kotlin
int[] items = new int[65]; items[65] = 5;
int[] items = new int[65]; if (65 < items.length) items[65] = 5;
Check bounds.
Java
print 'output'
print('output')
print needs parentheses.
Python
DELETE FROM users WHERE id=97
DELETE FROM users WHERE id=97;
Add semicolon.
SQL
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
let y = 37; y += 1;
let mut y = 37; y += 1;
Need mut to modify.
Rust
var x int
var x int
Correct.
Go
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
{{"status":"info" "title":92}}
{{"status":"info", "title":92}}
Add comma.
JSON
'world' + 57
'world' + str(57)
Can't add int to string.
Python
let list=vec![6,24,67]; let first=&list[0]; list.push(85);
let mut list=vec![6,24,67]; let first=list[0]; list.push(85);
Copy instead of reference.
Rust
fn baz() -> i32 {{ 67 }}
fn baz() -> i32 {{ 67 }}
Correct.
Rust
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++