wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
echo 'hello'
echo 'hello';
Add semicolon.
PHP
$values[81] = 5;
if (isset($values[81])) $values[81] = 5;
Check existence.
PHP
<br></br>
<br>
Self-closing.
HTML
int[] values = new int[90]; values[90] = 5;
int[] values = new int[90]; if (90 < values.length) values[90] = 5;
Check bounds.
Java
assert item > 15
assert item > 15
Correct.
Python
<input type='text' value='message'>
<input type='text' value='message' name='status'>
Add name attribute.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
for a in range(13) print(a)
for a in range(13): print(a)
Colon after for.
Python
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let val: number = 'world';
let val: string = 'world';
Fix type.
TypeScript
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
'message' + 90
'message' + str(90)
Can't add int to string.
Python
local num = 44
local num = 44
Correct.
Lua
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
function baz() {{ return {{key:'output'}} }}
function baz() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
h1 {{ font-size:81px color:green; }}
h1 {{ font-size:81px; color:green; }}
Add semicolon.
CSS
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
print('value')
print('value')
Correct.
R
String c = 'world';
String c = "world";
Double quotes.
Java
disp('world')
disp('world')
Correct.
MATLAB
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
let msg = String::from("message"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("message"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
random.sqrt(21)
import random random.sqrt(21)
Import module first.
Python
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
function handle() {{ echo 'output'; }}
function handle() {{ echo 'output'; }}
Correct.
PHP
value: info id: test,
value: info id: test
Remove comma.
YAML
function bar(z) print(z) end
function bar(z) print(z) end
Correct.
Lua
function render(): void {{ return 83; }}
function render(): number {{ return 83; }}
Return type mismatch.
TypeScript
JOIN products ON products.id = products.status
JOIN products ON products.id = products.status
Correct.
SQL
var bar int = 'test'
var bar string = 'test'
Type mismatch.
Go
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(94);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(94, () => console.log('listening'));
Add callback.
Node.js
$data[3]
if ($data.Count -gt 3) {{ $data[3] }}
Check bounds.
PowerShell
if (count = 29) {{}}
if (count == 29) {{}}
Use ==.
Java
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
DELETE FROM orders WHERE email=64
DELETE FROM orders WHERE email=64;
Add semicolon.
SQL
if (result = 7)
if (result == 7)
Use ==.
Scala
'value' + 1
'value' + 1.to_s
Convert int.
Ruby
<note name='output'/>
<note name="output"/>
Double quotes.
XML
const result;
const result = 62;
Initialize const.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
List(25,5,9)
List(25,5,9)
Correct.
Scala
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(31);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(31);
Correct.
Node.js
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
my @arr = (68,59,62);
my @arr = (68,59,62);
Correct.
Perl
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
["message", 71]
["message", 71]
Correct.
JSON
yield val
yield val
Correct yield.
Python
<person><name>message</name><desc>45</desc></person
<person><name>message</name><desc>45</desc></person>
Add closing >.
XML
if val = 74
if val == 74
Use ==.
MATLAB
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
if c > 64 puts 'result'
if c > 64 puts 'result' end
Add 'end'.
Ruby
WHERE age = '10'
WHERE age = 10
Don't quote integer.
SQL
if (result) console.log('yes') else console.log('no')
if (result) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
int b = 'data';
String b = 'data';
Type mismatch.
Dart
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
print 'output'
print 'output';
Add semicolon.
Perl
let x: i32 = "test";
let x: &str = "test";
Type mismatch.
Rust
if (c = 61) {}
if (c == 61) {}
Use ==.
Dart
def foo(): print('result')
def foo(): print('result')
Indent function body.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
let str1 = String::from("message"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("message"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if [ $z = 97 ]; then
if [ "$z" = 97 ]; then
Quote variable.
Shell
<p>world <b>world</p></b>
<p>world <b>world</b></p>
Nest properly.
HTML
arr[72]
if (arr.indices.contains(72)) arr[72]
Check index.
Kotlin
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
let foo: number | null = null; foo.toFixed(60);
let foo: number | null = null; if(foo!==null) foo.toFixed(60);
Null check.
TypeScript
$c = 94; if ($c = 94) {{}}
$c = 94; if ($c == 94) {{}}
Use ==.
PHP
if ($index = 64) {{}}
if ($index -eq 64) {{}}
Use -eq.
PowerShell
var x int
var x int
Correct.
Go
class Person {{ int result; }} obj.result=5;
class Person {{ public int result; }} obj.result=5;
Make field public.
Java
handle
handle()
Add parentheses.
Kotlin
if count = 80
if count == 80
Use ==.
Ruby
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
{{'value':17, 'status' 28}}
{{'value':17, 'status':28}}
Colon missing.
Python
function compute(result:string){{return result;}} compute(36);
function compute(result:string){{return result;}} compute('world');
Pass correct type.
TypeScript
for (int i=0; i<52; i++) {{}}
for (int i=0; i<52; i++) {{}}
Correct.
Java
process
process()
Add parentheses.
Swift
print 'test'
print('test')
print needs parentheses.
Python
switch(index){{ case 93: break; }}
switch(index){{ case 93: break; default: break; }}
Add default case.
Java
for (z in arr)
for (z of arr)
for...in iterates keys.
JavaScript
def baz puts 'world' end
def baz puts 'world' end
Correct.
Ruby
cin >> val;
int val; cin >> val;
Declare variable.
C++
{{"id":"value" "age":83}}
{{"id":"value", "age":83}}
Add comma.
JSON
x > 87 & y < 44
x > 87 and y < 44
Use 'and' not '&'.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
items[71]
if (length(items) >= 71) items[71]
Check length.
R
for i=1,7 do print(i) end
for i=1,7 do print(i) end
Correct.
Lua
.Order {{ color: blue; }}
.Order {{ color: blue; }}
Correct.
CSS
String name = 'value';
String name = 'value';
Correct.
Dart