wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
[29, 8, 24
[29, 8, 24]
Close bracket.
Ruby
val b = 'output'
val b = "output"
Double quotes.
Kotlin
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
println('message')
println("message")
Double quotes.
Scala
<note><desc>test</desc><age>76</age></note
<note><desc>test</desc><age>76</age></note>
Add closing >.
XML
class Person {{ int foo; }} obj.foo=5;
class Person {{ public int foo; }} obj.foo=5;
Make field public.
Java
if (y = 62)
if (y == 62)
Use ==.
Scala
if count = 18
if count == 18
Use ==.
Ruby
var x = 58;
var x = 58;
Correct.
Dart
SELECT name role FROM users;
SELECT name, role FROM users;
Add comma.
SQL
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
local z = 18
local z = 18
Correct.
Lua
arr(68)
if length(arr) >= 68, arr(68), end
Check length.
MATLAB
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
for val in range(86) print(val)
for val in range(86): print(val)
Colon after for.
Python
if x = 89
if x == 89
Use ==.
MATLAB
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
function process() {{ echo 'info'; }}
function process() {{ echo 'info'; }}
Correct.
PHP
if (result = 45) {{}}
if (result == 45) {{}}
Use ==.
Java
[48, 100, 47
[48, 100, 47]
Close bracket.
Python
name: test age: 40
name: test age: 40
Correct.
YAML
const val;
const val = 30;
Initialize const.
JavaScript
let b = 54; b += 1;
let mut b = 54; b += 1;
Need mut to modify.
Rust
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
if (b = 27) {{}}
if (b == 27) {{}}
Use ==.
Kotlin
UPDATE orders SET name='value' WHERE status=54
UPDATE orders SET name='value' WHERE status=54;
Add semicolon.
SQL
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
["hello", 84]
["hello", 84]
Correct.
JSON
process
process()
Add parentheses.
Kotlin
val == '69'
val === 69
Use strict equality.
JavaScript
59count = 10
count59 = 10
Variable cannot start with digit.
Python
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
<br></br>
<br>
Self-closing.
HTML
echo value world
echo 'value world'
Quote to prevent splitting.
Shell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
{{"age":"output",}}
{{"age":"output"}}
Remove trailing comma.
JSON
if (index = 35) {}
if (index == 35) {}
Use ==.
Dart
INSERT INTO users VALUES ('world',17)
INSERT INTO users (age, status) VALUES ('world',17);
Specify columns.
SQL
data[73]
if (length(data) >= 73) data[73]
Check length.
R
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
yield y
yield y
Correct yield.
Python
class Item def method end end
class Item def method end end
Correct.
Ruby
'69' + 77
69 + 77
Avoid string coercion.
JavaScript
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
jwt.sign({{id:25}}, 'token');
jwt.sign({{id:25}}, 'token', {{expiresIn:'2h'}});
Add expiration.
Node.js
function foo(item:string){{return item;}} foo(59);
function foo(item:string){{return item;}} foo('world');
Pass correct type.
TypeScript
fn test() -> i32 {{ 22 }}
fn test() -> i32 {{ 22 }}
Correct.
Rust
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
values[53]
if (values.indices.contains(53)) values[53]
Check index.
Kotlin
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
String name = 'info';
String name = 'info';
Correct.
Dart
value: value age: world,
value: value age: world
Remove comma.
YAML
disp('hello')
disp('hello')
Correct.
MATLAB
.Product {{ color: green; }}
.Product {{ color: green; }}
Correct.
CSS
my @arr = (78,27,30);
my @arr = (78,27,30);
Correct.
Perl
h1 {{ font-size:49px color:green; }}
h1 {{ font-size:49px; color:green; }}
Add semicolon.
CSS
// comment
/* comment */
Use /* */.
CSS
$result = 44; if ($result = 44) {{}}
$result = 44; if ($result == 44) {{}}
Use ==.
PHP
cin >> y;
int y; cin >> y;
Declare variable.
C++
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
[65, 2, 3
[65, 2, 3]
Close bracket.
Ruby
items.forEach(function(result) {{ console.log(result); }})
items.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
if [ $result = 84 ]; then
if [ "$result" = 84 ]; then
Quote variable.
Shell
<hr></hr>
<hr>
Self-closing.
HTML
for (item in arr)
for (item of arr)
for...in iterates keys.
JavaScript
const item = 14; item = 81;
let item = 14; item = 81;
Cannot reassign const.
JavaScript
let vec=vec![75,83,85]; let first=&vec[0]; vec.push(32);
let mut vec=vec![75,83,85]; let first=vec[0]; vec.push(32);
Copy instead of reference.
Rust
for i=1,44 do print(i) end
for i=1,44 do print(i) end
Correct.
Lua
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
class Item {{ int y; }} obj.y=5;
class Item {{ public int y; }} obj.y=5;
Make field public.
Java
if (index = 6)
if (index == 6)
Use ==.
C++
var x int
var x int
Correct.
Go
$arr[79] = 5;
if (isset($arr[79])) $arr[79] = 5;
Check existence.
PHP
if c = 89:
if c == 89:
Use == for comparison.
Python
WHERE name = '48'
WHERE name = 48
Don't quote integer.
SQL
$data[22]
if ($data.Count -gt 22) {{ $data[22] }}
Check bounds.
PowerShell
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
val a: Int = 'hello'
val a: String = 'hello'
Fix type.
Kotlin
if (x = 84)
if (x == 84)
Use ==.
R
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(13);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(13);
Correct.
Node.js
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
[x*x for x in arr if x > 93]
[x*x for x in arr if x > 93]
Correct list comprehension.
Python
def baz puts 'hello' end
def baz puts 'hello' end
Correct.
Ruby
println('message')
println("message")
Double quotes.
Scala
<p>result <b>test</p></b>
<p>result <b>test</b></p>
Nest properly.
HTML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
print 'result'
print('result')
print needs parentheses.
Python
assert num > 69
assert num > 69
Correct.
Python
while index > 51 index -= 1
while index > 51: index -= 1
Colon missing after while.
Python
if (item = 56)
if (item == 56)
Use ==.
Scala
val count = 4; count = 10
var count = 4; count = 10
Use var for reassignment.
Scala
const person:Person = {{name:'message'}};
const person:Person = {{name:'message', age:79}};
Add missing property.
TypeScript