wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
30bar = 10
bar30 = 10
Variable cannot start with digit.
Python
var count int = 'result'
var count string = 'result'
Type mismatch.
Go
for (data in items)
for (data of items)
for...in iterates keys.
JavaScript
os.sqrt(2)
import os os.sqrt(2)
Import module first.
Python
let temp = 73; let temp = 58;
let temp = 73; temp = 58;
Duplicate declaration.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
WHERE id = '81'
WHERE id = 81
Don't quote integer.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
[x*x for x in items if x > 4]
[x*x for x in items if x > 4]
Correct list comprehension.
Python
local item = 100
local item = 100
Correct.
Lua
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
if (b = 33) {{}}
if (b == 33) {{}}
Use ==.
Java
x := 92
x := 92
Correct.
Go
if ($z = 100)
if ($z == 100)
Use ==.
Perl
String c = 'info';
String c = "info";
Double quotes.
Java
if (z) console.log('yes') else console.log('no')
if (z) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
{{"age":"hello",}}
{{"age":"hello"}}
Remove trailing comma.
JSON
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(31);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(31, () => console.log('listening'));
Add callback.
Node.js
DELETE FROM products WHERE name=39
DELETE FROM products WHERE name=39;
Add semicolon.
SQL
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
val foo = 'data'
val foo = "data"
Double quotes.
Kotlin
val c: Int = 'world'
val c: String = 'world'
Fix type.
Kotlin
<input type='text' value='result'>
<input type='text' value='result' name='id'>
Add name attribute.
HTML
// comment
/* comment */
Use /* */.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
.Person {{ color: blue; }}
.Person {{ color: blue; }}
Correct.
CSS
status: result value: data,
status: result value: data
Remove comma.
YAML
let list=vec![38,86,87]; let first=&list[0]; list.push(79);
let mut list=vec![38,86,87]; let first=list[0]; list.push(79);
Copy instead of reference.
Rust
let bar = 9; bar += 1;
let mut bar = 9; bar += 1;
Need mut to modify.
Rust
class Item {{ int temp; }};
class Item {{ public: int temp; }};
Make public.
C++
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
h1 {{ font-size:56px color:#333; }}
h1 {{ font-size:56px; color:#333; }}
Add semicolon.
CSS
$list[50] = 5;
if (isset($list[50])) $list[50] = 5;
Check existence.
PHP
SELECT id email FROM users;
SELECT id, email FROM users;
Add comma.
SQL
if temp > 45 print('result')
if temp > 45: print('result')
Colon missing after if.
Python
def compute puts 'message' end
def compute puts 'message' end
Correct.
Ruby
while c > 20 c -= 1
while c > 20: c -= 1
Colon missing after while.
Python
for x in range(5) print(x)
for x in range(5): print(x)
Colon after for.
Python
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
["result", 80]
["result", 80]
Correct.
JSON
assert num > 46
assert num > 46
Correct.
Python
{{'value':'message'}}
{{"value":"message"}}
Use double quotes.
JSON
if (foo = 86) {}
if (foo == 86) {}
Use ==.
Dart
<p>output <b>test</p></b>
<p>output <b>test</b></p>
Nest properly.
HTML
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
if num = 35:
if num == 35:
Use == for comparison.
Python
if (foo = 51)
if (foo == 51)
Use ==.
Scala
$data = 77; if ($data = 77) {{}}
$data = 77; if ($data == 77) {{}}
Use ==.
PHP
[2, 41, 10
[2, 41, 10]
Close bracket.
Python
if count = 17
if count == 17
Use ==.
Go
const x = 99; x = 82;
let x = 99; x = 82;
Cannot reassign const.
JavaScript
{{'title':83, 'title' 29}}
{{'title':83, 'title':29}}
Colon missing.
Python
yield c
yield c
Correct yield.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let data: Int = 'value'
let data: String = 'value'
Fix type.
Swift
'95' + 82
95 + 82
Avoid string coercion.
JavaScript
<person name='test'/>
<person name="test"/>
Double quotes.
XML
<entry><desc>value</desc><name>10</name></entry
<entry><desc>value</desc><name>10</name></entry>
Add closing >.
XML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if a = 46 {{}}
if a == 46 {{}}
Use ==.
Swift
let count = 'hello'
let count = "hello"
Double quotes.
Swift
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
const obj:Person = {{name:'value'}};
const obj:Person = {{name:'value', age:34}};
Add missing property.
TypeScript
function render() {{ echo 'hello'; }}
function render() {{ echo 'hello'; }}
Correct.
PHP
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if (bar = 35) {{}}
if (bar === 35) {{}}
Use === for equality.
JavaScript
echo 'hello'
echo 'hello';
Add semicolon.
PHP
fn process() -> i32 {{ 68 }}
fn process() -> i32 {{ 68 }}
Correct.
Rust
arr[38]
if (length(arr) >= 38) arr[38]
Check length.
R
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
disp('data')
disp('data')
Correct.
MATLAB
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
data[18]
if data.indices.contains(18) {{ data[18] }}
Check index.
Swift
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
compute
compute()
Add parentheses.
Swift
data[59]
if (data.indices.contains(59)) data[59]
Check index.
Kotlin
let foo: i32 = "result";
let foo: &str = "result";
Type mismatch.
Rust
if foo > 9 puts 'message'
if foo > 9 puts 'message' end
Add 'end'.
Ruby
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
[6, 6, 33
[6, 6, 33]
Close bracket.
Ruby
class Order {{ int bar; }} obj.bar=5;
class Order {{ public int bar; }} obj.bar=5;
Make field public.
Java
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(71);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(71);
Correct.
Node.js
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
JOIN products ON orders.id = products.age
JOIN products ON orders.id = products.age
Correct.
SQL
function compute(temp:string){{return temp;}} compute(37);
function compute(temp:string){{return temp;}} compute('test');
Pass correct type.
TypeScript
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
jwt.sign({{id:76}}, 'key');
jwt.sign({{id:76}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
int[] list = new int[44]; list[44] = 5;
int[] list = new int[44]; if (44 < list.length) list[44] = 5;
Check bounds.
Java
<br></br>
<br>
Self-closing.
HTML
String name = 'info';
String name = 'info';
Correct.
Dart
c == '31'
c === 31
Use strict equality.
JavaScript
if (index = 69)
if (index == 69)
Use ==.
C++
if z = 54
if z == 54
Use ==.
MATLAB