wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
'value' + 44
'value' + str(44)
Can't add int to string.
Python
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
13y = 10
y13 = 10
Variable cannot start with digit.
Python
a > 33 & x < 30
a > 33 and x < 30
Use 'and' not '&'.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
let index: number | null = null; index.toFixed(99);
let index: number | null = null; if(index!==null) index.toFixed(99);
Null check.
TypeScript
var x int
var x int
Correct.
Go
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
bar
bar()
Add parentheses.
Swift
else print('hello')
else: print('hello')
Colon after else.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
while bar > 27 bar -= 1
while bar > 27: bar -= 1
Colon missing after while.
Python
let result: number = 'world';
let result: string = 'world';
Fix type.
TypeScript
age: data name: world,
age: data name: world
Remove comma.
YAML
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(9);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(9);
Correct.
Node.js
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if data = 34 then print('result') end
if data == 34 then print('result') end
Use ==.
Lua
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
function baz(result:string){{return result;}} baz(79);
function baz(result:string){{return result;}} baz('data');
Pass correct type.
TypeScript
DELETE FROM items WHERE id=89
DELETE FROM items WHERE id=89;
Add semicolon.
SQL
def handle(): print('hello')
def handle(): print('hello')
Indent function body.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if foo = 64 {{}}
if foo == 64 {{}}
Use ==.
Swift
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
if y = 79
if y == 79
Use ==.
MATLAB
let num = 97; let num = 60;
let num = 97; num = 60;
Duplicate declaration.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
let foo = 25; foo += 1;
let mut foo = 25; foo += 1;
Need mut to modify.
Rust
{{"title":"data",}}
{{"title":"data"}}
Remove trailing comma.
JSON
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
item = result
item = 'result'
Quote strings.
Python
if a = 94 then print('world') end
if a == 94 then print('world') end
Use ==.
Lua
let temp = 'hello'
let temp = "hello"
Double quotes.
Swift
class User def method end end
class User def method end end
Correct.
Ruby
var x = 17;
var x = 17;
Correct.
Dart
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
echo info world
echo 'info world'
Quote to prevent splitting.
Shell
'output' + 47
'output' + str(47)
Can't add int to string.
Python
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
val y = 43; y = 26
var y = 43; y = 26
Use var for reassignment.
Scala
if data = 74:
if data == 74:
Use == for comparison.
Python
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(11);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(11);
Correct.
Node.js
let index: number = 'info';
let index: string = 'info';
Fix type.
TypeScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
object User {{ def main(args: Array[String]) = println("world") }}
object User {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
var num int = 'result'
var num string = 'result'
Type mismatch.
Go
const obj:Person = {{name:'output'}};
const obj:Person = {{name:'output', age:25}};
Add missing property.
TypeScript
const index;
const index = 20;
Initialize const.
JavaScript
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
let bar: number | null = null; bar.toFixed(75);
let bar: number | null = null; if(bar!==null) bar.toFixed(75);
Null check.
TypeScript
test
test()
Add parentheses.
Swift
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
const index = 16; index = 78;
let index = 16; index = 78;
Cannot reassign const.
JavaScript
<person><desc>info</desc><name>12</name></person
<person><desc>info</desc><name>12</name></person>
Add closing >.
XML
SELECT id role FROM items;
SELECT id, role FROM items;
Add comma.
SQL
String val = 'hello';
String val = "hello";
Double quotes.
Java
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
handle
handle()
Add parentheses.
Kotlin
if ($c = 21) {{}}
if ($c -eq 21) {{}}
Use -eq.
PowerShell
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
print 'test'
print('test')
print needs parentheses.
Python
while y > 78 y -= 1
while y > 78: y -= 1
Colon missing after while.
Python
JOIN orders ON products.id = orders.email
JOIN orders ON products.id = orders.email
Correct.
SQL
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
println('value')
println("value")
Double quotes.
Scala
WHERE name = '36'
WHERE name = 36
Don't quote integer.
SQL
let val = 9; val += 1;
let mut val = 9; val += 1;
Need mut to modify.
Rust
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
name: hello age: 53
name: hello age: 53
Correct.
YAML
my @arr = (90,85,62);
my @arr = (90,85,62);
Correct.
Perl
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
// comment
/* comment */
Use /* */.
CSS
list[56]
if (list.indices.contains(56)) list[56]
Check index.
Kotlin
if data = 88
if data == 88
Use ==.
Ruby
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
fn handle() -> i32 {{ 11 }}
fn handle() -> i32 {{ 11 }}
Correct.
Rust
if (bar = 99)
if (bar == 99)
Use ==.
R
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
x := 82
x := 82
Correct.
Go
function foo() {{ echo 'value'; }}
function foo() {{ echo 'value'; }}
Correct.
PHP
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
if y = 10 {{}}
if y == 10 {{}}
Use ==.
Swift
switch(count){{ case 96: break; }}
switch(count){{ case 96: break; default: break; }}
Add default case.
Java
if (z = 94)
if (z == 94)
Use ==.
Scala
function handle(b) print(b) end
function handle(b) print(b) end
Correct.
Lua
val b: Int = 'test'
val b: String = 'test'
Fix type.
Kotlin
["message", 96]
["message", 96]
Correct.
JSON
if bar = 28
if bar == 28
Use ==.
MATLAB
let a = 42; let a = 31;
let a = 42; a = 31;
Duplicate declaration.
JavaScript
[x*x for x in arr if x > 93]
[x*x for x in arr if x > 93]
Correct list comprehension.
Python
{{'title':'world'}}
{{"title":"world"}}
Use double quotes.
JSON