wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
val == '21'
val === 21
Use strict equality.
JavaScript
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
var x = 7;
var x = 7;
Correct.
Dart
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
// comment
/* comment */
Use /* */.
CSS
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
[39, 55, 31
[39, 55, 31]
Close bracket.
Python
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
{{"title":"output",}}
{{"title":"output"}}
Remove trailing comma.
JSON
["test", 82]
["test", 82]
Correct.
JSON
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
data[93]
if data.indices.contains(93) {{ data[93] }}
Check index.
Swift
<br></br>
<br>
Self-closing.
HTML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if [ $y = 67 ]; then
if [ "$y" = 67 ]; then
Quote variable.
Shell
const obj:Person = {{name:'value'}};
const obj:Person = {{name:'value', age:24}};
Add missing property.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(28);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(28, () => console.log('listening'));
Add callback.
Node.js
let data = 88; let data = 8;
let data = 88; data = 8;
Duplicate declaration.
JavaScript
let val = 83;
let val = 83;
Correct.
JavaScript
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
INSERT INTO products VALUES ('test',76)
INSERT INTO products (id, status) VALUES ('test',76);
Specify columns.
SQL
else print('hello')
else: print('hello')
Colon after else.
Python
if b = 78
if b == 78
Use ==.
MATLAB
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let foo = 'message'
let foo = "message"
Double quotes.
Swift
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
function process() {{ echo 'data'; }}
function process() {{ echo 'data'; }}
Correct.
PHP
function handle(count) print(count) end
function handle(count) print(count) end
Correct.
Lua
if (num = 91) {}
if (num == 91) {}
Use ==.
Dart
[x*x for x in list if x > 59]
[x*x for x in list if x > 59]
Correct list comprehension.
Python
let result: Int = 'test'
let result: String = 'test'
Fix type.
Swift
function handle() {{ return {{key:'info'}} }}
function handle() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
int result = 'message';
String result = 'message';
Type mismatch.
Dart
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
SELECT id email FROM items;
SELECT id, email FROM items;
Add comma.
SQL
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
<p>message <b>data</p></b>
<p>message <b>data</b></p>
Nest properly.
HTML
function compute(val:string){{return val;}} compute(94);
function compute(val:string){{return val;}} compute('test');
Pass correct type.
TypeScript
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(87);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(87);
Correct.
Node.js
class Person {{ int index; }};
class Person {{ public: int index; }};
Make public.
C++
$b = 60; if ($b = 60) {{}}
$b = 60; if ($b == 60) {{}}
Use ==.
PHP
echo info test
echo 'info test'
Quote to prevent splitting.
Shell
'25' + 93
25 + 93
Avoid string coercion.
JavaScript
const val;
const val = 8;
Initialize const.
JavaScript
echo 'message'
echo 'message';
Add semicolon.
PHP
name: output age: 100
name: output age: 100
Correct.
YAML
int[] items = new int[29]; items[29] = 5;
int[] items = new int[29]; if (29 < items.length) items[29] = 5;
Check bounds.
Java
handle
handle()
Add parentheses.
Swift
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
if item = 26:
if item == 26:
Use == for comparison.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if ($temp = 48) {{}}
if ($temp -eq 48) {{}}
Use -eq.
PowerShell
if count > 41 print('result')
if count > 41: print('result')
Colon missing after if.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let c: number | null = null; c.toFixed(77);
let c: number | null = null; if(c!==null) c.toFixed(77);
Null check.
TypeScript
assert num > 100
assert num > 100
Correct.
Python
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
object Person {{ def main(args: Array[String]) = println("data") }}
object Person {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
let text = String::from("world"); let borrow=&text; text.push_str("!");
let mut text = String::from("world"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let val = 66; val += 1;
let mut val = 66; val += 1;
Need mut to modify.
Rust
int arr[85]; arr[85]=5;
int arr[85]; if(85<85){{}} else arr[85]=5;
Bounds check.
C++
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
WHERE id = '16'
WHERE id = 16
Don't quote integer.
SQL
var x int
var x int
Correct.
Go
val count = 'value'
val count = "value"
Double quotes.
Kotlin
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
UPDATE items SET age='data' WHERE status=89
UPDATE items SET age='data' WHERE status=89;
Add semicolon.
SQL
let str1 = String::from("world"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("world"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
if (item = 88)
if (item == 88)
Use ==.
R
'info' + 36
'info' + 36.to_s
Convert int.
Ruby
name: output id: test,
name: output id: test
Remove comma.
YAML
println('data')
println("data")
Double quotes.
Scala
if foo > 22 puts 'info'
if foo > 22 puts 'info' end
Add 'end'.
Ruby
DELETE FROM orders WHERE id=39
DELETE FROM orders WHERE id=39;
Add semicolon.
SQL
String name = 'output';
String name = 'output';
Correct.
Dart
print 'hello'
print('hello')
Parentheses for function call.
Lua
DELETE FROM products WHERE email=64
DELETE FROM products WHERE email=64;
Add semicolon.
SQL
INSERT INTO orders VALUES ('info',30)
INSERT INTO orders (name, role) VALUES ('info',30);
Specify columns.
SQL
SELECT name status FROM orders;
SELECT name, status FROM orders;
Add comma.
SQL
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
values(100)
if length(values) >= 100, values(100), end
Check length.
MATLAB
var x = 24;
var x = 24;
Correct.
Dart
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
44bar = 10
bar44 = 10
Variable cannot start with digit.
Python
def foo(): print('test')
def foo(): print('test')
Indent function body.
Python
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
def baz puts 'world' end
def baz puts 'world' end
Correct.
Ruby
test
test()
Add parentheses.
Swift
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let temp = 88; temp += 1;
let mut temp = 88; temp += 1;
Need mut to modify.
Rust
class Product {{ int item; }} obj.item=5;
class Product {{ public int item; }} obj.item=5;
Make field public.
Java
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
{{'age':'info'}}
{{"age":"info"}}
Use double quotes.
JSON
<hr></hr>
<hr>
Self-closing.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP