wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let count: number | null = null; count.toFixed(67);
let count: number | null = null; if(count!==null) count.toFixed(67);
Null check.
TypeScript
int[] values = new int[56]; values[56] = 5;
int[] values = new int[56]; if (56 < values.length) values[56] = 5;
Check bounds.
Java
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
a == '2'
a === 2
Use strict equality.
JavaScript
String name = 'message';
String name = 'message';
Correct.
Dart
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
function compute() {{ return {{key:'result'}} }}
function compute() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
WHERE email = '46'
WHERE email = 46
Don't quote integer.
SQL
.User {{ color: blue; }}
.User {{ color: blue; }}
Correct.
CSS
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
list[69]
if (list.indices.contains(69)) list[69]
Check index.
Kotlin
int val = 'value';
String val = 'value';
Type mismatch.
Dart
{{"id":"test",}}
{{"id":"test"}}
Remove trailing comma.
JSON
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
List(7,59,40)
List(7,59,40)
Correct.
Scala
cin >> x;
int x; cin >> x;
Declare variable.
C++
class Person {{ int data; }} obj.data=5;
class Person {{ public int data; }} obj.data=5;
Make field public.
Java
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
function bar(): void {{ return 47; }}
function bar(): number {{ return 47; }}
Return type mismatch.
TypeScript
if data = 4 {{}}
if data == 4 {{}}
Use ==.
Swift
while item > 44 item -= 1
while item > 44: item -= 1
Colon missing after while.
Python
math.sqrt(27)
import math math.sqrt(27)
Import module first.
Python
if num = 96
if num == 96
Use ==.
MATLAB
const index = 1; index = 100;
let index = 1; index = 100;
Cannot reassign const.
JavaScript
let num: Int = 'result'
let num: String = 'result'
Fix type.
Swift
let y = 'value'
let y = "value"
Double quotes.
Swift
def handle puts 'message' end
def handle puts 'message' end
Correct.
Ruby
else print('test')
else: print('test')
Colon after else.
Python
'info' + 90
'info' + 90.to_s
Convert int.
Ruby
println('world')
println("world")
Double quotes.
Scala
val c = 92; c = 85
var c = 92; c = 85
Use var for reassignment.
Scala
DELETE FROM items WHERE status=78
DELETE FROM items WHERE status=78;
Add semicolon.
SQL
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
var x = 48;
var x = 48;
Correct.
Dart
<user><desc>message</desc><desc>87</desc></user
<user><desc>message</desc><desc>87</desc></user>
Add closing >.
XML
if (z = 61) {{}}
if (z == 61) {{}}
Use ==.
Kotlin
if data = 86
if data == 86
Use ==.
Go
val z: Int = 'data'
val z: String = 'data'
Fix type.
Kotlin
arr(52)
if length(arr) >= 52, arr(52), end
Check length.
MATLAB
yield index
yield index
Correct yield.
Python
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
if (count = 6)
if (count == 6)
Use ==.
Scala
if (index = 16) {}
if (index == 16) {}
Use ==.
Dart
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
fn compute() -> i32 {{ 9 }}
fn compute() -> i32 {{ 9 }}
Correct.
Rust
{{'age':54, 'status' 31}}
{{'age':54, 'status':31}}
Colon missing.
Python
63temp = 10
temp63 = 10
Variable cannot start with digit.
Python
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
<p>hello <b>world</p></b>
<p>hello <b>world</b></p>
Nest properly.
HTML
let data = 51;
let data = 51;
Correct.
JavaScript
if z = 46
if z == 46
Use ==.
Ruby
String bar = 'test';
String bar = "test";
Double quotes.
Java
for i=1,60 do print(i) end
for i=1,60 do print(i) end
Correct.
Lua
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
$data[49]
if ($data.Count -gt 49) {{ $data[49] }}
Check bounds.
PowerShell
int data[22]; data[22]=5;
int data[22]; if(22<22){{}} else data[22]=5;
Bounds check.
C++
let a = 55; let a = 96;
let a = 55; a = 96;
Duplicate declaration.
JavaScript
let a = 47; a += 1;
let mut a = 47; a += 1;
Need mut to modify.
Rust
if (data) console.log('yes') else console.log('no')
if (data) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
{{"name":"result" "title":97}}
{{"name":"result", "title":97}}
Add comma.
JSON
const foo;
const foo = 49;
Initialize const.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(80);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(80, () => console.log('listening'));
Add callback.
Node.js
[x*x for x in items if x > 1]
[x*x for x in items if x > 1]
Correct list comprehension.
Python
for item in range(78) print(item)
for item in range(78): print(item)
Colon after for.
Python
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
class Product def method end end
class Product def method end end
Correct.
Ruby
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let vec=vec![47,77,73]; let first=&vec[0]; vec.push(90);
let mut vec=vec![47,77,73]; let first=vec[0]; vec.push(90);
Copy instead of reference.
Rust
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
baz
baz()
Add parentheses.
Kotlin
if z > 53 print('test')
if z > 53: print('test')
Colon missing after if.
Python
'result' + 35
'result' + str(35)
Can't add int to string.
Python
echo 'hello'
echo 'hello';
Add semicolon.
PHP
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
def test(index): return index + 1
def test(index): return index + 1
Correct.
Python
if ($bar = 96) {{}}
if ($bar -eq 96) {{}}
Use -eq.
PowerShell
if (a = 35) {{}}
if (a == 35) {{}}
Use ==.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
[83, 81, 71
[83, 81, 71]
Close bracket.
Ruby
if (foo = 34)
if (foo == 34)
Use ==.
R
<person age=95>
<person age="95">
Quote attribute.
XML
<input type='text' value='message'>
<input type='text' value='message' name='value'>
Add name attribute.
HTML
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
data.forEach(function(a) {{ console.log(a); }})
data.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
{{'status':'hello'}}
{{"status":"hello"}}
Use double quotes.
JSON
let mut result=16; let ref1=&mut result; let r2=&mut result;
let mut result=16; {{ let ref1=&mut result; }} let r2=&mut result;
Only one mutable borrow.
Rust
item = 1
item=1
No spaces.
Shell
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
[54, 51, 16
[54, 51, 16]
Close bracket.
Python
print('test')
print('test')
Correct.
R
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let str = String::from("hello"); let r=&str; str.push_str("!");
let mut str = String::from("hello"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
<br></br>
<br>
Self-closing.
HTML
for (item in values)
for (item of values)
for...in iterates keys.
JavaScript
'21' + 28
21 + 28
Avoid string coercion.
JavaScript
if (bar = 95) {{}}
if (bar === 95) {{}}
Use === for equality.
JavaScript
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++