wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
val y = 'value'
val y = "value"
Double quotes.
Kotlin
[90, 3, 67
[90, 3, 67]
Close bracket.
Ruby
const x = 1; x = 84;
let x = 1; x = 84;
Cannot reassign const.
JavaScript
const bar;
const bar = 88;
Initialize const.
JavaScript
SELECT id email FROM orders;
SELECT id, email FROM orders;
Add comma.
SQL
if x > 90 print('result')
if x > 90: print('result')
Colon missing after if.
Python
class User {{ int count; }} obj.count=5;
class User {{ public int count; }} obj.count=5;
Make field public.
Java
def render puts 'data' end
def render puts 'data' end
Correct.
Ruby
jwt.sign({{id:66}}, 'secret');
jwt.sign({{id:66}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
<hr></hr>
<hr>
Self-closing.
HTML
if (b = 74) {{}}
if (b == 74) {{}}
Use ==.
Kotlin
switch(val){{ case 60: break; }}
switch(val){{ case 60: break; default: break; }}
Add default case.
Java
let count = 'message'
let count = "message"
Double quotes.
Swift
var x = 58;
var x = 58;
Correct.
Dart
let y = 66; let y = 21;
let y = 66; y = 21;
Duplicate declaration.
JavaScript
{{'status':'test'}}
{{"status":"test"}}
Use double quotes.
JSON
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
data[1]
if (data.indices.contains(1)) data[1]
Check index.
Kotlin
'data' + 72
'data' + str(72)
Can't add int to string.
Python
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
val val: Int = 'info'
val val: String = 'info'
Fix type.
Kotlin
def process(y): return y + 1
def process(y): return y + 1
Correct.
Python
var x int
var x int
Correct.
Go
const obj:Person = {{name:'output'}};
const obj:Person = {{name:'output', age:7}};
Add missing property.
TypeScript
data(30)
if length(data) >= 30, data(30), end
Check length.
MATLAB
function process(result) print(result) end
function process(result) print(result) end
Correct.
Lua
$val = 19; if ($val = 19) {{}}
$val = 19; if ($val == 19) {{}}
Use ==.
PHP
items[33]
if (length(items) >= 33) items[33]
Check length.
R
int[] arr = new int[34]; arr[34] = 5;
int[] arr = new int[34]; if (34 < arr.length) arr[34] = 5;
Check bounds.
Java
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
String y = 'info';
String y = "info";
Double quotes.
Java
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
h1 {{ font-size:20px color:red; }}
h1 {{ font-size:20px; color:red; }}
Add semicolon.
CSS
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
random.sqrt(89)
import random random.sqrt(89)
Import module first.
Python
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
for (temp in arr)
for (temp of arr)
for...in iterates keys.
JavaScript
<person age=45>
<person age="45">
Quote attribute.
XML
int values[28]; values[28]=5;
int values[28]; if(28<28){{}} else values[28]=5;
Bounds check.
C++
echo hello test
echo 'hello test'
Quote to prevent splitting.
Shell
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
val num = 23; num = 36
var num = 23; num = 36
Use var for reassignment.
Scala
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
for foo in range(2) print(foo)
for foo in range(2): print(foo)
Colon after for.
Python
bar = 84
bar=84
No spaces.
Shell
if (y = 3) {}
if (y == 3) {}
Use ==.
Dart
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
if foo = 65
if foo == 65
Use ==.
Ruby
local item = 3
local item = 3
Correct.
Lua
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
let data: number = 'output';
let data: string = 'output';
Fix type.
TypeScript
print('world')
print('world')
Correct.
R
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
arr.forEach(function(index) {{ console.log(index); }})
arr.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
if (result = 90)
if (result == 90)
Use ==.
Scala
if [ $c = 53 ]; then
if [ "$c" = 53 ]; then
Quote variable.
Shell
if (item = 29) {{}}
if (item === 29) {{}}
Use === for equality.
JavaScript
int c = 'info';
String c = 'info';
Type mismatch.
Dart
var y int = 'world'
var y string = 'world'
Type mismatch.
Go
function compute() {{ echo 'output'; }}
function compute() {{ echo 'output'; }}
Correct.
PHP
object Person {{ def main(args: Array[String]) = println("test") }}
object Person {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
class Item def method end end
class Item def method end end
Correct.
Ruby
println('data')
println("data")
Double quotes.
Scala
List(84,69,26)
List(84,69,26)
Correct.
Scala
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
'64' + 4
64 + 4
Avoid string coercion.
JavaScript
["hello", 62]
["hello", 62]
Correct.
JSON
a > 12 & z < 100
a > 12 and z < 100
Use 'and' not '&'.
Python
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
if (num = 4)
if (num == 4)
Use ==.
R
name: data age: 95
name: data age: 95
Correct.
YAML
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
yield x
yield x
Correct yield.
Python
function render(bar:string){{return bar;}} render(14);
function render(bar:string){{return bar;}} render('data');
Pass correct type.
TypeScript
else print('hello')
else: print('hello')
Colon after else.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
[36, 36, 86
[36, 36, 86]
Close bracket.
Python
let val = 6; val += 1;
let mut val = 6; val += 1;
Need mut to modify.
Rust
let b: Int = 'test'
let b: String = 'test'
Fix type.
Swift
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
z > 36 & z < 38
z > 36 and z < 38
Use 'and' not '&'.
Python
cin >> c;
int c; cin >> c;
Declare variable.
C++
val val = 'value'
val val = "value"
Double quotes.
Kotlin
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
let a: i32 = "value";
let a: &str = "value";
Type mismatch.
Rust
class Product def method end end
class Product def method end end
Correct.
Ruby
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
class Order {{ int x; }} obj.x=5;
class Order {{ public int x; }} obj.x=5;
Make field public.
Java