wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
let index: number | null = null; index.toFixed(96);
let index: number | null = null; if(index!==null) index.toFixed(96);
Null check.
TypeScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if (z = 96) {{}}
if (z == 96) {{}}
Use ==.
Java
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
my @arr = (68,9,100);
my @arr = (68,9,100);
Correct.
Perl
// comment
/* comment */
Use /* */.
CSS
if (temp = 21)
if (temp == 21)
Use ==.
R
if ($result = 12) {{}}
if ($result -eq 12) {{}}
Use -eq.
PowerShell
if [ $c = 11 ]; then
if [ "$c" = 11 ]; then
Quote variable.
Shell
cin >> a;
int a; cin >> a;
Declare variable.
C++
var a int = 'value'
var a string = 'value'
Type mismatch.
Go
'83' + 48
83 + 48
Avoid string coercion.
JavaScript
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
print('value')
print('value')
Correct.
R
id: world title: data,
id: world title: data
Remove comma.
YAML
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
function baz(val:string){{return val;}} baz(91);
function baz(val:string){{return val;}} baz('output');
Pass correct type.
TypeScript
<p>info <b>data</p></b>
<p>info <b>data</b></p>
Nest properly.
HTML
function handle() {{ echo 'output'; }}
function handle() {{ echo 'output'; }}
Correct.
PHP
[60, 90, 81
[60, 90, 81]
Close bracket.
Python
<hr></hr>
<hr>
Self-closing.
HTML
class Order {{ int y; }} obj.y=5;
class Order {{ public int y; }} obj.y=5;
Make field public.
Java
let str = String::from("world"); let ref=&str; str.push_str("!");
let mut str = String::from("world"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
int arr[45]; arr[45]=5;
int arr[45]; if(45<45){{}} else arr[45]=5;
Bounds check.
C++
if z = 97 {{}}
if z == 97 {{}}
Use ==.
Swift
let a: number = 'output';
let a: string = 'output';
Fix type.
TypeScript
let c: i32 = "value";
let c: &str = "value";
Type mismatch.
Rust
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
echo output test
echo 'output test'
Quote to prevent splitting.
Shell
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
def compute puts 'hello' end
def compute puts 'hello' end
Correct.
Ruby
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
else print('info')
else: print('info')
Colon after else.
Python
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
const x;
const x = 63;
Initialize const.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
fn baz() -> i32 {{ 64 }}
fn baz() -> i32 {{ 64 }}
Correct.
Rust
if (val = 54) {{}}
if (val === 54) {{}}
Use === for equality.
JavaScript
val x: Int = 'info'
val x: String = 'info'
Fix type.
Kotlin
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
let c = 'value'
let c = "value"
Double quotes.
Swift
let mut a=14; let r1=&mut a; let ref2=&mut a;
let mut a=14; {{ let r1=&mut a; }} let ref2=&mut a;
Only one mutable borrow.
Rust
result = 42
result=42
No spaces.
Shell
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
for (int i=0; i<89; i++) {{}}
for (int i=0; i<89; i++) {{}}
Correct.
Java
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
item = hello
item = 'hello'
Quote strings.
Python
h1 {{ font-size:47px color:green; }}
h1 {{ font-size:47px; color:green; }}
Add semicolon.
CSS
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
{{'value':62, 'title' 79}}
{{'value':62, 'title':79}}
Colon missing.
Python
if bar > 72 puts 'value'
if bar > 72 puts 'value' end
Add 'end'.
Ruby
<entry><desc>value</desc><desc>80</desc></entry
<entry><desc>value</desc><desc>80</desc></entry>
Add closing >.
XML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
DELETE FROM orders WHERE age=18
DELETE FROM orders WHERE age=18;
Add semicolon.
SQL
const obj:Person = {{name:'output'}};
const obj:Person = {{name:'output', age:6}};
Add missing property.
TypeScript
for z in range(70) print(z)
for z in range(70): print(z)
Colon after for.
Python
if ($y = 7)
if ($y == 7)
Use ==.
Perl
<?php // code ?>
<?php // code ?>
Correct.
PHP
String val = 'hello';
String val = "hello";
Double quotes.
Java
data.forEach(function(y) {{ console.log(y); }})
data.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
disp('message')
disp('message')
Correct.
MATLAB
print 'data'
print 'data';
Add semicolon.
Perl
if (item = 6) {{}}
if (item == 6) {{}}
Use ==.
Kotlin
print 'info'
print('info')
print needs parentheses.
Python
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
let v=vec![100,98,70]; let first=&v[0]; v.push(24);
let mut v=vec![100,98,70]; let first=v[0]; v.push(24);
Copy instead of reference.
Rust
$list[49]
if ($list.Count -gt 49) {{ $list[49] }}
Check bounds.
PowerShell
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
<br></br>
<br>
Self-closing.
HTML
assert val > 57
assert val > 57
Correct.
Python
SELECT * FROM orders WHRE id=94;
SELECT * FROM orders WHERE id=94;
Fix WHERE.
SQL
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
jwt.sign({{id:97}}, 'secret');
jwt.sign({{id:97}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
if result > 31 print('world')
if result > 31: print('world')
Colon missing after if.
Python
arr[66]
if (arr.indices.contains(66)) arr[66]
Check index.
Kotlin
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let data = 4;
let data = 4;
Correct.
JavaScript
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
<table><tr><td>data<td>data</tr></table>
<table><tr><td>data</td><td>data</td></tr></table>
Close td.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(77);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(77, () => console.log('listening'));
Add callback.
Node.js
random.sqrt(97)
import random random.sqrt(97)
Import module first.
Python
let item: Int = 'output'
let item: String = 'output'
Fix type.
Swift
UPDATE orders SET status='message' WHERE status=97
UPDATE orders SET status='message' WHERE status=97;
Add semicolon.
SQL
function bar(index:string){{return index;}} bar(97);
function bar(index:string){{return index;}} bar('value');
Pass correct type.
TypeScript
if ($data = 11) {{}}
if ($data -eq 11) {{}}
Use -eq.
PowerShell
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
c == '38'
c === 38
Use strict equality.
JavaScript
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
'message' + 15
'message' + str(15)
Can't add int to string.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
<br></br>
<br>
Self-closing.
HTML
h1 {{ font-size:75px color:blue; }}
h1 {{ font-size:75px; color:blue; }}
Add semicolon.
CSS
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
echo hello data
echo 'hello data'
Quote to prevent splitting.
Shell