wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
if c = 41
if c == 41
Use ==.
Go
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if val > 92 print('world')
if val > 92: print('world')
Colon missing after if.
Python
let str1 = String::from("result"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("result"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
18count = 10
count18 = 10
Variable cannot start with digit.
Python
local y = 22
local y = 22
Correct.
Lua
[x*x for x in list if x > 51]
[x*x for x in list if x > 51]
Correct list comprehension.
Python
print 'message'
print('message')
print needs parentheses.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
$list[42]
if ($list.Count -gt 42) {{ $list[42] }}
Check bounds.
PowerShell
if ($b = 98)
if ($b == 98)
Use ==.
Perl
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
cin >> data;
int data; cin >> data;
Declare variable.
C++
for temp in range(16) print(temp)
for temp in range(16): print(temp)
Colon after for.
Python
INSERT INTO items VALUES ('hello',6)
INSERT INTO items (age, email) VALUES ('hello',6);
Specify columns.
SQL
const result = 96; result = 74;
let result = 96; result = 74;
Cannot reassign const.
JavaScript
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
function process(): void {{ return 73; }}
function process(): number {{ return 73; }}
Return type mismatch.
TypeScript
list[56]
if (length(list) >= 56) list[56]
Check length.
R
process
process()
Add parentheses.
Swift
String result = 'output';
String result = "output";
Double quotes.
Java
for (int i=0; i<40; i++) {{}}
for (int i=0; i<40; i++) {{}}
Correct.
Java
let mut foo=80; let r1=&mut foo; let r2=&mut foo;
let mut foo=80; {{ let r1=&mut foo; }} let r2=&mut foo;
Only one mutable borrow.
Rust
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
b == '92'
b === 92
Use strict equality.
JavaScript
{{"title":"hello" "value":16}}
{{"title":"hello", "value":16}}
Add comma.
JSON
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
disp('value')
disp('value')
Correct.
MATLAB
items[99]
if items.indices.contains(99) {{ items[99] }}
Check index.
Swift
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
let b: number | null = null; b.toFixed(38);
let b: number | null = null; if(b!==null) b.toFixed(38);
Null check.
TypeScript
if item = 16 {{}}
if item == 16 {{}}
Use ==.
Swift
<p>value <b>hello</p></b>
<p>value <b>hello</b></p>
Nest properly.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if (z = 23)
if (z == 23)
Use ==.
C++
var x = 18;
var x = 18;
Correct.
Dart
switch(temp){{ case 12: break; }}
switch(temp){{ case 12: break; default: break; }}
Add default case.
Java
<input type='text' value='info'>
<input type='text' value='info' name='value'>
Add name attribute.
HTML
let data: Int = 'output'
let data: String = 'output'
Fix type.
Swift
class Person {{ int c; }} obj.c=5;
class Person {{ public int c; }} obj.c=5;
Make field public.
Java
<person name='hello'/>
<person name="hello"/>
Double quotes.
XML
UPDATE users SET name='test' WHERE email=41
UPDATE users SET name='test' WHERE email=41;
Add semicolon.
SQL
{{'value':35, 'age' 45}}
{{'value':35, 'age':45}}
Colon missing.
Python
// comment
/* comment */
Use /* */.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let y: number = 'result';
let y: string = 'result';
Fix type.
TypeScript
if (c = 94) {}
if (c == 94) {}
Use ==.
Dart
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
object Item {{ def main(args: Array[String]) = println("world") }}
object Item {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
const temp;
const temp = 77;
Initialize const.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
random.sqrt(98)
import random random.sqrt(98)
Import module first.
Python
name: output age: 9
name: output age: 9
Correct.
YAML
yield item
yield item
Correct yield.
Python
val data: Int = 'hello'
val data: String = 'hello'
Fix type.
Kotlin
print 'hello'
print('hello')
Parentheses for function call.
Lua
def handle(): print('hello')
def handle(): print('hello')
Indent function body.
Python
data[8]
if (data.indices.contains(8)) data[8]
Check index.
Kotlin
h1 {{ font-size:5px color:green; }}
h1 {{ font-size:5px; color:green; }}
Add semicolon.
CSS
["hello", 85]
["hello", 85]
Correct.
JSON
<person age=65>
<person age="65">
Quote attribute.
XML
let a = 'info'
let a = "info"
Double quotes.
Swift
val a = 'world'
val a = "world"
Double quotes.
Kotlin
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
print('result')
print('result')
Correct.
R
if (a = 91) {{}}
if (a == 91) {{}}
Use ==.
Java
z > 43 & x < 57
z > 43 and x < 57
Use 'and' not '&'.
Python
assert val > 22
assert val > 22
Correct.
Python
my @arr = (25,8,81);
my @arr = (25,8,81);
Correct.
Perl
let v=vec![60,37,20]; let first=&v[0]; v.push(70);
let mut v=vec![60,37,20]; let first=v[0]; v.push(70);
Copy instead of reference.
Rust
if item = 49
if item == 49
Use ==.
MATLAB
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
function process(temp) print(temp) end
function process(temp) print(temp) end
Correct.
Lua
val b = 62; b = 28
var b = 62; b = 28
Use var for reassignment.
Scala
[94, 11, 5
[94, 11, 5]
Close bracket.
Python
if x = 36 then print('output') end
if x == 36 then print('output') end
Use ==.
Lua
if ($y = 87) {{}}
if ($y -eq 87) {{}}
Use -eq.
PowerShell
if num > 16 puts 'output'
if num > 16 puts 'output' end
Add 'end'.
Ruby
if (item = 8)
if (item == 8)
Use ==.
Scala
function process() {{ echo 'world'; }}
function process() {{ echo 'world'; }}
Correct.
PHP
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
else print('value')
else: print('value')
Colon after else.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(33);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(33, () => console.log('listening'));
Add callback.
Node.js
process
process()
Add parentheses.
Kotlin
var x int
var x int
Correct.
Go
SELECT * FROM orders WHRE status=44;
SELECT * FROM orders WHERE status=44;
Fix WHERE.
SQL
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
if (foo = 46)
if (foo == 46)
Use ==.
R
fn bar() -> i32 {{ 88 }}
fn bar() -> i32 {{ 88 }}
Correct.
Rust