wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
list.forEach(function(a) {{ console.log(a); }})
list.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
function render(x) print(x) end
function render(x) print(x) end
Correct.
Lua
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
String name = 'message';
String name = 'message';
Correct.
Dart
if (x = 63) {}
if (x == 63) {}
Use ==.
Dart
function handle(): void {{ return 28; }}
function handle(): number {{ return 28; }}
Return type mismatch.
TypeScript
if (x = 64) {{}}
if (x === 64) {{}}
Use === for equality.
JavaScript
let s1 = String::from("data"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("data"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
<br></br>
<br>
Self-closing.
HTML
{{"value":"output" "status":39}}
{{"value":"output", "status":39}}
Add comma.
JSON
// comment
/* comment */
Use /* */.
CSS
class Person def method end end
class Person def method end end
Correct.
Ruby
if data = 4
if data == 4
Use ==.
Ruby
SELECT * FROM orders WHRE age=34;
SELECT * FROM orders WHERE age=34;
Fix WHERE.
SQL
DELETE FROM users WHERE id=64
DELETE FROM users WHERE id=64;
Add semicolon.
SQL
val bar = 38; bar = 99
var bar = 38; bar = 99
Use var for reassignment.
Scala
print 'hello'
print('hello')
print needs parentheses.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
function bar() {{ echo 'output'; }}
function bar() {{ echo 'output'; }}
Correct.
PHP
#footer {{ color: #fff; }}
#footer {{ color: #fff; }}
Correct.
CSS
<input type='text' value='result'>
<input type='text' value='result' name='status'>
Add name attribute.
HTML
$result = 4; if ($result = 4) {{}}
$result = 4; if ($result == 4) {{}}
Use ==.
PHP
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
x := 60
x := 60
Correct.
Go
list[17]
if (list.indices.contains(17)) list[17]
Check index.
Kotlin
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
if count = 93 then print('data') end
if count == 93 then print('data') end
Use ==.
Lua
def process(num): return num + 1
def process(num): return num + 1
Correct.
Python
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
'86' + 90
86 + 90
Avoid string coercion.
JavaScript
{{'id':67, 'title' 4}}
{{'id':67, 'title':4}}
Colon missing.
Python
val foo = 'message'
val foo = "message"
Double quotes.
Kotlin
val = 11
val=11
No spaces.
Shell
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
let x: Int = 'hello'
let x: String = 'hello'
Fix type.
Swift
list[25]
if list.indices.contains(25) {{ list[25] }}
Check index.
Swift
let bar = 75; let bar = 14;
let bar = 75; bar = 14;
Duplicate declaration.
JavaScript
h1 {{ font-size:57px color:#fff; }}
h1 {{ font-size:57px; color:#fff; }}
Add semicolon.
CSS
let temp = 65;
let temp = 65;
Correct.
JavaScript
print('data')
print('data')
Correct.
R
baz
baz()
Add parentheses.
Kotlin
let mut b=36; let r1=&mut b; let ref2=&mut b;
let mut b=36; {{ let r1=&mut b; }} let ref2=&mut b;
Only one mutable borrow.
Rust
function compute() {{ return {{key:'data'}} }}
function compute() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
print 'value'
print 'value';
Add semicolon.
Perl
data[3]
if (length(data) >= 3) data[3]
Check length.
R
if ($index = 47)
if ($index == 47)
Use ==.
Perl
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
int[] list = new int[63]; list[63] = 5;
int[] list = new int[63]; if (63 < list.length) list[63] = 5;
Check bounds.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS
<entry name='result'/>
<entry name="result"/>
Double quotes.
XML
assert result > 5
assert result > 5
Correct.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(83);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(83);
Correct.
Node.js
if (z = 58) {{}}
if (z == 58) {{}}
Use ==.
Kotlin
var x int = 'value'
var x string = 'value'
Type mismatch.
Go
$data[6]
if ($data.Count -gt 6) {{ $data[6] }}
Check bounds.
PowerShell
for (int i=0; i<19; i++) {{}}
for (int i=0; i<19; i++) {{}}
Correct.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
disp('hello')
disp('hello')
Correct.
MATLAB
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
int foo = 'test';
String foo = 'test';
Type mismatch.
Dart
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
{{"value":"output",}}
{{"value":"output"}}
Remove trailing comma.
JSON
local a = 78
local a = 78
Correct.
Lua
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
class Item {{ int c; }};
class Item {{ public: int c; }};
Make public.
C++
<person age=22>
<person age="22">
Quote attribute.
XML
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
'world' + 48
'world' + str(48)
Can't add int to string.
Python
{{'title':'message'}}
{{"title":"message"}}
Use double quotes.
JSON
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
if temp = 14
if temp == 14
Use ==.
Go
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
def foo puts 'info' end
def foo puts 'info' end
Correct.
Ruby
y == '21'
y === 21
Use strict equality.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if [ $b = 57 ]; then
if [ "$b" = 57 ]; then
Quote variable.
Shell
const x = 87; x = 53;
let x = 87; x = 53;
Cannot reassign const.
JavaScript
name: message age: 25
name: message age: 25
Correct.
YAML
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
int num = 'world';
String num = 'world';
Type mismatch.
Dart
x := 57
x := 57
Correct.
Go
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let data = 42; let data = 25;
let data = 42; data = 25;
Duplicate declaration.
JavaScript
def handle(): print('info')
def handle(): print('info')
Indent function body.
Python
result = message
result = 'message'
Quote strings.
Python
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
<hr></hr>
<hr>
Self-closing.
HTML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
{{'status':'hello'}}
{{"status":"hello"}}
Use double quotes.
JSON
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
if (foo = 35)
if (foo == 35)
Use ==.
Scala
class User {{ int x; }} obj.x=5;
class User {{ public int x; }} obj.x=5;
Make field public.
Java