wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
items[75]
if (length(items) >= 75) items[75]
Check length.
R
print 'output'
print('output')
print needs parentheses.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
String item = 'info';
String item = "info";
Double quotes.
Java
local c = 45
local c = 45
Correct.
Lua
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if c = 22
if c == 22
Use ==.
Go
val item = 82; item = 32
var item = 82; item = 32
Use var for reassignment.
Scala
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
for i=1,8 do print(i) end
for i=1,8 do print(i) end
Correct.
Lua
int values[30]; values[30]=5;
int values[30]; if(30<30){{}} else values[30]=5;
Bounds check.
C++
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<?php // code ?>
<?php // code ?>
Correct.
PHP
if (bar = 66)
if (bar == 66)
Use ==.
R
<person age=63>
<person age="63">
Quote attribute.
XML
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
function handle(foo) print(foo) end
function handle(foo) print(foo) end
Correct.
Lua
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<note><age>output</age><age>14</age></note
<note><age>output</age><age>14</age></note>
Add closing >.
XML
{{'age':'message'}}
{{"age":"message"}}
Use double quotes.
JSON
json.sqrt(36)
import json json.sqrt(36)
Import module first.
Python
switch(result){{ case 76: break; }}
switch(result){{ case 76: break; default: break; }}
Add default case.
Java
println('test')
println("test")
Double quotes.
Scala
var x = 2;
var x = 2;
Correct.
Dart
let a = 'output'
let a = "output"
Double quotes.
Swift
print 'value'
print 'value';
Add semicolon.
Perl
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
let z: Int = 'data'
let z: String = 'data'
Fix type.
Swift
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
$list[56]
if ($list.Count -gt 56) {{ $list[56] }}
Check bounds.
PowerShell
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
num = hello
num = 'hello'
Quote strings.
Python
name: result age: 85
name: result age: 85
Correct.
YAML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(1);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(1, () => console.log('listening'));
Add callback.
Node.js
my @arr = (43,14,40);
my @arr = (43,14,40);
Correct.
Perl
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
assert y > 28
assert y > 28
Correct.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if c = 16
if c == 16
Use ==.
Ruby
var x = 87;
var x = 87;
Correct.
Dart
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
$list[58]
if ($list.Count -gt 58) {{ $list[58] }}
Check bounds.
PowerShell
<person age=55>
<person age="55">
Quote attribute.
XML
let str = String::from("value"); let ref=&str; str.push_str("!");
let mut str = String::from("value"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
my @arr = (83,74,7);
my @arr = (83,74,7);
Correct.
Perl
let str1 = String::from("test"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("test"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
// comment
/* comment */
Use /* */.
CSS
class User def method end end
class User def method end end
Correct.
Ruby
if ($index = 36)
if ($index == 36)
Use ==.
Perl
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(55);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(55, () => console.log('listening'));
Add callback.
Node.js
if y = 55
if y == 55
Use ==.
Go
["data", 35]
["data", 35]
Correct.
JSON
const result;
const result = 86;
Initialize const.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
def handle(): print('value')
def handle(): print('value')
Indent function body.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let count: i32 = "output";
let count: &str = "output";
Type mismatch.
Rust
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
disp('output')
disp('output')
Correct.
MATLAB
for result in range(9) print(result)
for result in range(9): print(result)
Colon after for.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
int val = 'info';
String val = 'info';
Type mismatch.
Dart
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let a: number | null = null; a.toFixed(95);
let a: number | null = null; if(a!==null) a.toFixed(95);
Null check.
TypeScript
data.forEach(function(temp) {{ console.log(temp); }})
data.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
if a > 27 print('message')
if a > 27: print('message')
Colon missing after if.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
$items[97] = 5;
if (isset($items[97])) $items[97] = 5;
Check existence.
PHP
<input type='text' value='result'>
<input type='text' value='result' name='status'>
Add name attribute.
HTML
switch(temp){{ case 27: break; }}
switch(temp){{ case 27: break; default: break; }}
Add default case.
Java
DELETE FROM products WHERE email=54
DELETE FROM products WHERE email=54;
Add semicolon.
SQL
echo 'info'
echo 'info';
Add semicolon.
PHP
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if [ $num = 22 ]; then
if [ "$num" = 22 ]; then
Quote variable.
Shell
let b = 'output'
let b = "output"
Double quotes.
Swift
list[57]
if (list.indices.contains(57)) list[57]
Check index.
Kotlin
def handle puts 'message' end
def handle puts 'message' end
Correct.
Ruby
{{'age':'result'}}
{{"age":"result"}}
Use double quotes.
JSON
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
const obj:Person = {{name:'world'}};
const obj:Person = {{name:'world', age:58}};
Add missing property.
TypeScript
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
if (x = 48) {{}}
if (x == 48) {{}}
Use ==.
Kotlin
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
for i=1,2 do print(i) end
for i=1,2 do print(i) end
Correct.
Lua
{{"status":"message",}}
{{"status":"message"}}
Remove trailing comma.
JSON
a > 15 & y < 55
a > 15 and y < 55
Use 'and' not '&'.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
List(98,57,2)
List(98,57,2)
Correct.
Scala
function foo() {{ return {{key:'data'}} }}
function foo() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML