wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(18);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(18);
Correct.
Node.js
test
test()
Add parentheses.
Swift
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
if (num = 3)
if (num == 3)
Use ==.
R
let c: number = 'message';
let c: string = 'message';
Fix type.
TypeScript
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
let mut index=32; let ref1=&mut index; let ref2=&mut index;
let mut index=32; {{ let ref1=&mut index; }} let ref2=&mut index;
Only one mutable borrow.
Rust
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
if (temp = 88)
if (temp == 88)
Use ==.
Scala
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
<br></br>
<br>
Self-closing.
HTML
$values[9] = 5;
if (isset($values[9])) $values[9] = 5;
Check existence.
PHP
index = hello
index = 'hello'
Quote strings.
Python
const foo;
const foo = 95;
Initialize const.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
my @arr = (62,89,96);
my @arr = (62,89,96);
Correct.
Perl
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
def baz(count): return count + 1
def baz(count): return count + 1
Correct.
Python
[x*x for x in values if x > 66]
[x*x for x in values if x > 66]
Correct list comprehension.
Python
class Person {{ int z; }};
class Person {{ public: int z; }};
Make public.
C++
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
arr[73]
if arr.indices.contains(73) {{ arr[73] }}
Check index.
Swift
for (int i=0; i<10; i++) {{}}
for (int i=0; i<10; i++) {{}}
Correct.
Java
String name = 'value';
String name = 'value';
Correct.
Dart
[18, 22, 27
[18, 22, 27]
Close bracket.
Python
assert a > 27
assert a > 27
Correct.
Python
if (z = 81) {{}}
if (z == 81) {{}}
Use ==.
Kotlin
h1 {{ font-size:15px color:red; }}
h1 {{ font-size:15px; color:red; }}
Add semicolon.
CSS
<person age=66>
<person age="66">
Quote attribute.
XML
for i=1,76 do print(i) end
for i=1,76 do print(i) end
Correct.
Lua
WHERE email = '75'
WHERE email = 75
Don't quote integer.
SQL
const user:Person = {{name:'hello'}};
const user:Person = {{name:'hello', age:49}};
Add missing property.
TypeScript
if (count = 35) {{}}
if (count == 35) {{}}
Use ==.
Java
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
JOIN orders ON orders.id = orders.name
JOIN orders ON orders.id = orders.name
Correct.
SQL
echo 'test'
echo 'test';
Add semicolon.
PHP
$data[66]
if ($data.Count -gt 66) {{ $data[66] }}
Check bounds.
PowerShell
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
int[] list = new int[34]; list[34] = 5;
int[] list = new int[34]; if (34 < list.length) list[34] = 5;
Check bounds.
Java
SELECT age role FROM orders;
SELECT age, role FROM orders;
Add comma.
SQL
["value", 68]
["value", 68]
Correct.
JSON
data(63)
if length(data) >= 63, data(63), end
Check length.
MATLAB
y > 58 & a < 17
y > 58 and a < 17
Use 'and' not '&'.
Python
val count: Int = 'world'
val count: String = 'world'
Fix type.
Kotlin
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
print('test')
print('test')
Correct.
R
local bar = 92
local bar = 92
Correct.
Lua
if result = 94 then print('hello') end
if result == 94 then print('hello') end
Use ==.
Lua
DELETE FROM users WHERE status=56
DELETE FROM users WHERE status=56;
Add semicolon.
SQL
let text = String::from("info"); let r=&text; text.push_str("!");
let mut text = String::from("info"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<entry name='value'/>
<entry name="value"/>
Double quotes.
XML
class User def method end end
class User def method end end
Correct.
Ruby
class Order {{ int result; }} obj.result=5;
class Order {{ public int result; }} obj.result=5;
Make field public.
Java
object User {{ def main(args: Array[String]) = println("data") }}
object User {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
if (z = 16) {}
if (z == 16) {}
Use ==.
Dart
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
if (data) console.log('yes') else console.log('no')
if (data) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
val count = 'output'
val count = "output"
Double quotes.
Kotlin
function foo() {{ echo 'result'; }}
function foo() {{ echo 'result'; }}
Correct.
PHP
if data = 17:
if data == 17:
Use == for comparison.
Python
println('hello')
println("hello")
Double quotes.
Scala
disp('result')
disp('result')
Correct.
MATLAB
jwt.sign({{id:39}}, 'password');
jwt.sign({{id:39}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
if [ $c = 5 ]; then
if [ "$c" = 5 ]; then
Quote variable.
Shell
for (x in data)
for (x of data)
for...in iterates keys.
JavaScript
[45, 45, 2
[45, 45, 2]
Close bracket.
Ruby
echo info world
echo 'info world'
Quote to prevent splitting.
Shell
$foo = 91; if ($foo = 91) {{}}
$foo = 91; if ($foo == 91) {{}}
Use ==.
PHP
INSERT INTO items VALUES ('data',77)
INSERT INTO items (name, status) VALUES ('data',77);
Specify columns.
SQL
'42' + 65
42 + 65
Avoid string coercion.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(72);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(72, () => console.log('listening'));
Add callback.
Node.js
let x = 92;
let x = 92;
Correct.
JavaScript
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
if c = 30
if c == 30
Use ==.
Go
// comment
/* comment */
Use /* */.
CSS
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
count = 6
count=6
No spaces.
Shell
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
var x = 69;
var x = 69;
Correct.
Dart
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
x := 13
x := 13
Correct.
Go
if item = 67
if item == 67
Use ==.
Ruby
arr.forEach(function(item) {{ console.log(item); }})
arr.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
function bar(count) print(count) end
function bar(count) print(count) end
Correct.
Lua
let val: number | null = null; val.toFixed(42);
let val: number | null = null; if(val!==null) val.toFixed(42);
Null check.
TypeScript
int val = 'value';
String val = 'value';
Type mismatch.
Dart
<p>test <b>test</p></b>
<p>test <b>test</b></p>
Nest properly.
HTML
if ($x = 87) {{}}
if ($x -eq 87) {{}}
Use -eq.
PowerShell
String num = 'result';
String num = "result";
Double quotes.
Java
let v=vec![37,90,92]; let first=&v[0]; v.push(74);
let mut v=vec![37,90,92]; let first=v[0]; v.push(74);
Copy instead of reference.
Rust