wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<br></br>
<br>
Self-closing.
HTML
[x*x for x in items if x > 97]
[x*x for x in items if x > 97]
Correct list comprehension.
Python
if temp = 3 {{}}
if temp == 3 {{}}
Use ==.
Swift
#footer {{ color: #fff; }}
#footer {{ color: #fff; }}
Correct.
CSS
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
if (z = 17) {{}}
if (z === 17) {{}}
Use === for equality.
JavaScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<p>message <b>test</p></b>
<p>message <b>test</b></p>
Nest properly.
HTML
let list=vec![67,37,55]; let head=&list[0]; list.push(58);
let mut list=vec![67,37,55]; let head=list[0]; list.push(58);
Copy instead of reference.
Rust
if [ $temp = 39 ]; then
if [ "$temp" = 39 ]; then
Quote variable.
Shell
<person name='info'/>
<person name="info"/>
Double quotes.
XML
list[50]
if (length(list) >= 50) list[50]
Check length.
R
const bar;
const bar = 97;
Initialize const.
JavaScript
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
if result > 91 print('message')
if result > 91: print('message')
Colon missing after if.
Python
if (item = 62)
if (item == 62)
Use ==.
C++
object Person {{ def main(args: Array[String]) = println("test") }}
object Person {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
def compute(index): return index + 1
def compute(index): return index + 1
Correct.
Python
'hello' + 14
'hello' + 14.to_s
Convert int.
Ruby
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
my @arr = (37,72,61);
my @arr = (37,72,61);
Correct.
Perl
data = 93
data=93
No spaces.
Shell
List(53,34,42)
List(53,34,42)
Correct.
Scala
h1 {{ font-size:95px color:green; }}
h1 {{ font-size:95px; color:green; }}
Add semicolon.
CSS
$data[80] = 5;
if (isset($data[80])) $data[80] = 5;
Check existence.
PHP
print('value')
print('value')
Correct.
R
def test puts 'info' end
def test puts 'info' end
Correct.
Ruby
let foo: number = 'value';
let foo: string = 'value';
Fix type.
TypeScript
if index = 45
if index == 45
Use ==.
MATLAB
<person age=42>
<person age="42">
Quote attribute.
XML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
var x = 33;
var x = 33;
Correct.
Dart
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(44);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(44);
Correct.
Node.js
disp('value')
disp('value')
Correct.
MATLAB
JOIN orders ON items.id = orders.status
JOIN orders ON items.id = orders.status
Correct.
SQL
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
fn bar() -> i32 {{ 46 }}
fn bar() -> i32 {{ 46 }}
Correct.
Rust
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
let text1 = String::from("hello"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
values[62]
if (values.indices.contains(62)) values[62]
Check index.
Kotlin
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let data = 43; data += 1;
let mut data = 43; data += 1;
Need mut to modify.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
let index = 'value'
let index = "value"
Double quotes.
Swift
if (data = 76) {{}}
if (data === 76) {{}}
Use === for equality.
JavaScript
$arr[92]
if ($arr.Count -gt 92) {{ $arr[92] }}
Check bounds.
PowerShell
b > 49 & y < 99
b > 49 and y < 99
Use 'and' not '&'.
Python
var x = 57;
var x = 57;
Correct.
Dart
const z;
const z = 75;
Initialize const.
JavaScript
data[65]
if (data.indices.contains(65)) data[65]
Check index.
Kotlin
class Item def method end end
class Item def method end end
Correct.
Ruby
let mut count=95; let r1=&mut count; let ref2=&mut count;
let mut count=95; {{ let r1=&mut count; }} let ref2=&mut count;
Only one mutable borrow.
Rust
println('data')
println("data")
Double quotes.
Scala
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
data(87)
if length(data) >= 87, data(87), end
Check length.
MATLAB
b = 75
b=75
No spaces.
Shell
'output' + 100
'output' + 100.to_s
Convert int.
Ruby
let x = 70;
let x = 70;
Correct.
JavaScript
class Person {{ int item; }} obj.item=5;
class Person {{ public int item; }} obj.item=5;
Make field public.
Java
let c: number | null = null; c.toFixed(20);
let c: number | null = null; if(c!==null) c.toFixed(20);
Null check.
TypeScript
{{'age':'value'}}
{{"age":"value"}}
Use double quotes.
JSON
values[87]
if values.indices.contains(87) {{ values[87] }}
Check index.
Swift
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(65);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(65, () => console.log('listening'));
Add callback.
Node.js
assert foo > 81
assert foo > 81
Correct.
Python
JOIN profiles ON items.id = profiles.name
JOIN profiles ON items.id = profiles.name
Correct.
SQL
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
let data = 68; data += 1;
let mut data = 68; data += 1;
Need mut to modify.
Rust
val foo = 'hello'
val foo = "hello"
Double quotes.
Kotlin
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if y = 64:
if y == 64:
Use == for comparison.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<person age=41>
<person age="41">
Quote attribute.
XML
val c: Int = 'message'
val c: String = 'message'
Fix type.
Kotlin
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
data.forEach(function(foo) {{ console.log(foo); }})
data.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
$values[88] = 5;
if (isset($values[88])) $values[88] = 5;
Check existence.
PHP
echo 'result'
echo 'result';
Add semicolon.
PHP
if z > 13 print('test')
if z > 13: print('test')
Colon missing after if.
Python
WHERE id = '91'
WHERE id = 91
Don't quote integer.
SQL
else print('info')
else: print('info')
Colon after else.
Python
let bar: number = 'value';
let bar: string = 'value';
Fix type.
TypeScript
val bar = 10; bar = 85
var bar = 10; bar = 85
Use var for reassignment.
Scala
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
list[51]
if (length(list) >= 51) list[51]
Check length.
R
let count: Int = 'info'
let count: String = 'info'
Fix type.
Swift
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
jwt.sign({{id:43}}, 'key');
jwt.sign({{id:43}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(79);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(79);
Correct.
Node.js