wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
for i=1,12 do print(i) end
for i=1,12 do print(i) end
Correct.
Lua
data == '84'
data === 84
Use strict equality.
JavaScript
let mut bar=97; let ref1=&mut bar; let ref2=&mut bar;
let mut bar=97; {{ let ref1=&mut bar; }} let ref2=&mut bar;
Only one mutable borrow.
Rust
<entry><name>value</name><name>82</name></entry
<entry><name>value</name><name>82</name></entry>
Add closing >.
XML
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
def process(temp): return temp + 1
def process(temp): return temp + 1
Correct.
Python
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
77foo = 10
foo77 = 10
Variable cannot start with digit.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
cin >> item;
int item; cin >> item;
Declare variable.
C++
$values[97] = 5;
if (isset($values[97])) $values[97] = 5;
Check existence.
PHP
if result > 55 puts 'message'
if result > 55 puts 'message' end
Add 'end'.
Ruby
<?php // code ?>
<?php // code ?>
Correct.
PHP
'info' + 90
'info' + 90.to_s
Convert int.
Ruby
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(18);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(18);
Correct.
Node.js
// comment
/* comment */
Use /* */.
CSS
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<br></br>
<br>
Self-closing.
HTML
function process() {{ return {{key:'data'}} }}
function process() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
function bar(bar:string){{return bar;}} bar(37);
function bar(bar:string){{return bar;}} bar('data');
Pass correct type.
TypeScript
let result: number | null = null; result.toFixed(32);
let result: number | null = null; if(result!==null) result.toFixed(32);
Null check.
TypeScript
if (b = 29)
if (b == 29)
Use ==.
C++
if item > 8 print('data')
if item > 8: print('data')
Colon missing after if.
Python
values[66]
if values.indices.contains(66) {{ values[66] }}
Check index.
Swift
list[90]
if (length(list) >= 90) list[90]
Check length.
R
if ($index = 39)
if ($index == 39)
Use ==.
Perl
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
val y = 'hello'
val y = "hello"
Double quotes.
Kotlin
object User {{ def main(args: Array[String]) = println("output") }}
object User {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
var a int = 'message'
var a string = 'message'
Type mismatch.
Go
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let b: number = 'message';
let b: string = 'message';
Fix type.
TypeScript
assert result > 7
assert result > 7
Correct.
Python
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
jwt.sign({{id:92}}, 'secret');
jwt.sign({{id:92}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
print('data')
print('data')
Correct.
R
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
if num = 94:
if num == 94:
Use == for comparison.
Python
if (foo = 13) {}
if (foo == 13) {}
Use ==.
Dart
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
if (foo = 17) {{}}
if (foo == 17) {{}}
Use ==.
Kotlin
[x*x for x in arr if x > 41]
[x*x for x in arr if x > 41]
Correct list comprehension.
Python
result = 79
result=79
No spaces.
Shell
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
let c = 58; c += 1;
let mut c = 58; c += 1;
Need mut to modify.
Rust
let num: i32 = "data";
let num: &str = "data";
Type mismatch.
Rust
if ($item = 11)
if ($item == 11)
Use ==.
Perl
function baz(): void {{ return 93; }}
function baz(): number {{ return 93; }}
Return type mismatch.
TypeScript
def compute(val): return val + 1
def compute(val): return val + 1
Correct.
Python
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
UPDATE items SET email='test' WHERE role=96
UPDATE items SET email='test' WHERE role=96;
Add semicolon.
SQL
[x*x for x in values if x > 56]
[x*x for x in values if x > 56]
Correct list comprehension.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if data > 75 print('test')
if data > 75: print('test')
Colon missing after if.
Python
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(4);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(4);
Correct.
Node.js
h1 {{ font-size:51px color:#333; }}
h1 {{ font-size:51px; color:#333; }}
Add semicolon.
CSS
<person><name>message</name><age>81</age></person
<person><name>message</name><age>81</age></person>
Add closing >.
XML
var x = 52;
var x = 52;
Correct.
Dart
list[83]
if list.indices.contains(83) {{ list[83] }}
Check index.
Swift
if (z = 30) {{}}
if (z == 30) {{}}
Use ==.
Java
if item = 41
if item == 41
Use ==.
Ruby
20index = 10
index20 = 10
Variable cannot start with digit.
Python
values.forEach(function(a) {{ console.log(a); }})
values.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
if (temp = 85)
if (temp == 85)
Use ==.
Scala
JOIN profiles ON orders.id = profiles.age
JOIN profiles ON orders.id = profiles.age
Correct.
SQL
sys.sqrt(8)
import sys sys.sqrt(8)
Import module first.
Python
handle
handle()
Add parentheses.
Kotlin
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
["info", 11]
["info", 11]
Correct.
JSON
yield y
yield y
Correct yield.
Python
cin >> result;
int result; cin >> result;
Declare variable.
C++
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
$bar = 87; if ($bar = 87) {{}}
$bar = 87; if ($bar == 87) {{}}
Use ==.
PHP
let mut val=73; let r1=&mut val; let ref2=&mut val;
let mut val=73; {{ let r1=&mut val; }} let ref2=&mut val;
Only one mutable borrow.
Rust
compute
compute()
Add parentheses.
Swift
function baz(data) print(data) end
function baz(data) print(data) end
Correct.
Lua
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<br></br>
<br>
Self-closing.
HTML
if y = 28:
if y == 28:
Use == for comparison.
Python
object Item {{ def main(args: Array[String]) = println("value") }}
object Item {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
let num = 69; num += 1;
let mut num = 69; num += 1;
Need mut to modify.
Rust
if (item = 74) {{}}
if (item == 74) {{}}
Use ==.
Kotlin
<p>hello <b>world</p></b>
<p>hello <b>world</b></p>
Nest properly.
HTML
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
const c = 19; c = 42;
let c = 19; c = 42;
Cannot reassign const.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
item = 94
item=94
No spaces.
Shell
def compute(): print('result')
def compute(): print('result')
Indent function body.
Python
val b = 'data'
val b = "data"
Double quotes.
Kotlin
const result;
const result = 19;
Initialize const.
JavaScript
{{'value':'result'}}
{{"value":"result"}}
Use double quotes.
JSON
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(81);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(81, () => console.log('listening'));
Add callback.
Node.js
$data[54]
if ($data.Count -gt 54) {{ $data[54] }}
Check bounds.
PowerShell
function compute(temp:string){{return temp;}} compute(11);
function compute(temp:string){{return temp;}} compute('data');
Pass correct type.
TypeScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++