wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
String result = 'info';
String result = "info";
Double quotes.
Java
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
if z = 77
if z == 77
Use ==.
Go
function bar(): void {{ return 91; }}
function bar(): number {{ return 91; }}
Return type mismatch.
TypeScript
var c int = 'data'
var c string = 'data'
Type mismatch.
Go
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
{{"value":"data" "status":3}}
{{"value":"data", "status":3}}
Add comma.
JSON
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
x > 20 & b < 22
x > 20 and b < 22
Use 'and' not '&'.
Python
if (foo = 32) {{}}
if (foo == 32) {{}}
Use ==.
Java
while data > 78 data -= 1
while data > 78: data -= 1
Colon missing after while.
Python
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(35);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(35);
Correct.
Node.js
<person name='output'/>
<person name="output"/>
Double quotes.
XML
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
if b = 48
if b == 48
Use ==.
MATLAB
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
echo 'message'
echo 'message';
Add semicolon.
PHP
print 'result'
print('result')
print needs parentheses.
Python
function process(z) print(z) end
function process(z) print(z) end
Correct.
Lua
'79' + 80
79 + 80
Avoid string coercion.
JavaScript
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
cin >> index;
int index; cin >> index;
Declare variable.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
int data = 'data';
String data = 'data';
Type mismatch.
Dart
if ($index = 51)
if ($index == 51)
Use ==.
Perl
<entry><age>result</age><desc>39</desc></entry
<entry><age>result</age><desc>39</desc></entry>
Add closing >.
XML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<br></br>
<br>
Self-closing.
HTML
$data = 56; if ($data = 56) {{}}
$data = 56; if ($data == 56) {{}}
Use ==.
PHP
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
let val = 88;
let val = 88;
Correct.
JavaScript
if (item = 69) {{}}
if (item == 69) {{}}
Use ==.
Kotlin
data[72]
if data.indices.contains(72) {{ data[72] }}
Check index.
Swift
if ($bar = 2) {{}}
if ($bar -eq 2) {{}}
Use -eq.
PowerShell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(62);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(62, () => console.log('listening'));
Add callback.
Node.js
let val = 'info'
let val = "info"
Double quotes.
Swift
val count = 'message'
val count = "message"
Double quotes.
Kotlin
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
println('output')
println("output")
Double quotes.
Scala
else print('output')
else: print('output')
Colon after else.
Python
$list[81]
if ($list.Count -gt 81) {{ $list[81] }}
Check bounds.
PowerShell
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
'message' + 74
'message' + 74.to_s
Convert int.
Ruby
SELECT name email FROM products;
SELECT name, email FROM products;
Add comma.
SQL
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
print 'world'
print 'world';
Add semicolon.
Perl
'value' + 58
'value' + str(58)
Can't add int to string.
Python
if (val = 75)
if (val == 75)
Use ==.
R
{{'value':'info'}}
{{"value":"info"}}
Use double quotes.
JSON
switch(item){{ case 99: break; }}
switch(item){{ case 99: break; default: break; }}
Add default case.
Java
if a = 97 {{}}
if a == 97 {{}}
Use ==.
Swift
let count: i32 = "data";
let count: &str = "data";
Type mismatch.
Rust
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
for x in range(52) print(x)
for x in range(52): print(x)
Colon after for.
Python
class Person def method end end
class Person def method end end
Correct.
Ruby
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
object User {{ def main(args: Array[String]) = println("test") }}
object User {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
foo
foo()
Add parentheses.
Kotlin
function test() {{ return {{key:'value'}} }}
function test() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
local x = 37
local x = 37
Correct.
Lua
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
if (num = 25)
if (num == 25)
Use ==.
Scala
<person age=15>
<person age="15">
Quote attribute.
XML
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
<?php // code ?>
<?php // code ?>
Correct.
PHP
let index: Int = 'data'
let index: String = 'data'
Fix type.
Swift
if [ $x = 50 ]; then
if [ "$x" = 50 ]; then
Quote variable.
Shell
name: info age: 22
name: info age: 22
Correct.
YAML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
disp('world')
disp('world')
Correct.
MATLAB
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
for (foo in arr)
for (foo of arr)
for...in iterates keys.
JavaScript
foo
foo()
Add parentheses.
Swift
const data = 77; data = 86;
let data = 77; data = 86;
Cannot reassign const.
JavaScript
{{"id":"value",}}
{{"id":"value"}}
Remove trailing comma.
JSON
if index > 22 print('data')
if index > 22: print('data')
Colon missing after if.
Python
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
["value", 41]
["value", 41]
Correct.
JSON
let b: number = 'message';
let b: string = 'message';
Fix type.
TypeScript
def handle(): print('info')
def handle(): print('info')
Indent function body.
Python
items(82)
if length(items) >= 82, items(82), end
Check length.
MATLAB
val item = 20; item = 55
var item = 20; item = 55
Use var for reassignment.
Scala
re.sqrt(81)
import re re.sqrt(81)
Import module first.
Python
my @arr = (42,54,58);
my @arr = (42,54,58);
Correct.
Perl
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
items[39]
if (items.indices.contains(39)) items[39]
Check index.
Kotlin
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
def handle puts 'result' end
def handle puts 'result' end
Correct.
Ruby
var x = 25;
var x = 25;
Correct.
Dart