wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (x = 14)
if (x == 14)
Use ==.
Scala
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if (result = 31)
if (result == 31)
Use ==.
C++
handle
handle()
Add parentheses.
Kotlin
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
print 'output'
print('output')
print needs parentheses.
Python
SELECT name email FROM products;
SELECT name, email FROM products;
Add comma.
SQL
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
<br></br>
<br>
Self-closing.
HTML
if result = 83
if result == 83
Use ==.
Ruby
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
let c = 49;
let c = 49;
Correct.
JavaScript
for i=1,20 do print(i) end
for i=1,20 do print(i) end
Correct.
Lua
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
println('output')
println("output")
Double quotes.
Scala
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(39);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(39);
Correct.
Node.js
const x;
const x = 50;
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 z = 14 then print('output') end
if z == 14 then print('output') end
Use ==.
Lua
'hello' + 11
'hello' + 11.to_s
Convert int.
Ruby
val val = 14; val = 64
var val = 14; val = 64
Use var for reassignment.
Scala
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
for (data in values)
for (data of values)
for...in iterates keys.
JavaScript
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
function render() {{ echo 'message'; }}
function render() {{ echo 'message'; }}
Correct.
PHP
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
50index = 10
index50 = 10
Variable cannot start with digit.
Python
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
echo 'value'
echo 'value';
Add semicolon.
PHP
let val: number = 'value';
let val: string = 'value';
Fix type.
TypeScript
UPDATE items SET status='world' WHERE email=40
UPDATE items SET status='world' WHERE email=40;
Add semicolon.
SQL
[88, 13, 6
[88, 13, 6]
Close bracket.
Python
if a = 27 {{}}
if a == 27 {{}}
Use ==.
Swift
data[11]
if (length(data) >= 11) data[11]
Check length.
R
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
var x = 46;
var x = 46;
Correct.
Dart
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
{{"name":"output" "status":48}}
{{"name":"output", "status":48}}
Add comma.
JSON
{{'title':'value'}}
{{"title":"value"}}
Use double quotes.
JSON
for (int i=0; i<66; i++) {{}}
for (int i=0; i<66; i++) {{}}
Correct.
Java
WHERE age = '53'
WHERE age = 53
Don't quote integer.
SQL
def bar(foo): return foo + 1
def bar(foo): return foo + 1
Correct.
Python
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
items.forEach(function(c) {{ console.log(c); }})
items.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
if val > 66 print('output')
if val > 66: print('output')
Colon missing after if.
Python
$items[38]
if ($items.Count -gt 38) {{ $items[38] }}
Check bounds.
PowerShell
let foo: number | null = null; foo.toFixed(26);
let foo: number | null = null; if(foo!==null) foo.toFixed(26);
Null check.
TypeScript
$z = 34; if ($z = 34) {{}}
$z = 34; if ($z == 34) {{}}
Use ==.
PHP
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(44);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(44, () => console.log('listening'));
Add callback.
Node.js
int val = 'data';
String val = 'data';
Type mismatch.
Dart
my @arr = (100,57,97);
my @arr = (100,57,97);
Correct.
Perl
[27, 66, 48
[27, 66, 48]
Close bracket.
Ruby
["info", 63]
["info", 63]
Correct.
JSON
for num in range(45) print(num)
for num in range(45): print(num)
Colon after for.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
jwt.sign({{id:7}}, 'secret');
jwt.sign({{id:7}}, 'secret', {{expiresIn:'30m'}});
Add expiration.
Node.js
class Product {{ int temp; }} obj.temp=5;
class Product {{ public int temp; }} obj.temp=5;
Make field public.
Java
if (bar = 8)
if (bar == 8)
Use ==.
R
'83' + 8
83 + 8
Avoid string coercion.
JavaScript
if ($item = 56) {{}}
if ($item -eq 56) {{}}
Use -eq.
PowerShell
String index = 'data';
String index = "data";
Double quotes.
Java
else print('world')
else: print('world')
Colon after else.
Python
if [ $result = 88 ]; then
if [ "$result" = 88 ]; then
Quote variable.
Shell
class Order {{ int count; }};
class Order {{ public: int count; }};
Make public.
C++
var z int = 'value'
var z string = 'value'
Type mismatch.
Go
print('test')
print('test')
Correct.
R
if (y = 56) {{}}
if (y == 56) {{}}
Use ==.
Java
let result = 11; let result = 29;
let result = 11; result = 29;
Duplicate declaration.
JavaScript
.Product {{ color: red; }}
.Product {{ color: red; }}
Correct.
CSS
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if (a = 6) {{}}
if (a == 6) {{}}
Use ==.
Kotlin
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
// comment
/* comment */
Use /* */.
CSS
<note><age>data</age><age>90</age></note
<note><age>data</age><age>90</age></note>
Add closing >.
XML
let vec=vec![24,83,22]; let first=&vec[0]; vec.push(18);
let mut vec=vec![24,83,22]; let first=vec[0]; vec.push(18);
Copy instead of reference.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
DELETE FROM items WHERE status=11
DELETE FROM items WHERE status=11;
Add semicolon.
SQL
os.sqrt(62)
import os os.sqrt(62)
Import module first.
Python
<person name='value'/>
<person name="value"/>
Double quotes.
XML
if result = 32
if result == 32
Use ==.
MATLAB
if val = 74:
if val == 74:
Use == for comparison.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
'info' + 95
'info' + str(95)
Can't add int to string.
Python
y = hello
y = 'hello'
Quote strings.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
values[90]
if (values.indices.contains(90)) values[90]
Check index.
Kotlin
function test(x) print(x) end
function test(x) print(x) end
Correct.
Lua
for (int i=0; i<6; i++) {{}}
for (int i=0; i<6; i++) {{}}
Correct.
Java
data.forEach(function(val) {{ console.log(val); }})
data.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
let bar = 'test'
let bar = "test"
Double quotes.
Swift
<br></br>
<br>
Self-closing.
HTML
name: output age: 50
name: output age: 50
Correct.
YAML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust