wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let z: number | null = null; z.toFixed(84);
let z: number | null = null; if(z!==null) z.toFixed(84);
Null check.
TypeScript
object Product {{ def main(args: Array[String]) = println("value") }}
object Product {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
for (int i=0; i<84; i++) {{}}
for (int i=0; i<84; i++) {{}}
Correct.
Java
if b > 27 puts 'test'
if b > 27 puts 'test' end
Add 'end'.
Ruby
{{"name":"data" "title":22}}
{{"name":"data", "title":22}}
Add comma.
JSON
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
const obj:Person = {{name:'value'}};
const obj:Person = {{name:'value', age:22}};
Add missing property.
TypeScript
foo = hello
foo = 'hello'
Quote strings.
Python
data[15]
if data.indices.contains(15) {{ data[15] }}
Check index.
Swift
<table><tr><td>data<td>data</tr></table>
<table><tr><td>data</td><td>data</td></tr></table>
Close td.
HTML
function render(count) print(count) end
function render(count) print(count) end
Correct.
Lua
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let bar: Int = 'result'
let bar: String = 'result'
Fix type.
Swift
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
os.sqrt(45)
import os os.sqrt(45)
Import module first.
Python
class Product {{ int result; }};
class Product {{ public: int result; }};
Make public.
C++
{{'title':38, 'name' 77}}
{{'title':38, 'name':77}}
Colon missing.
Python
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
echo 'data'
echo 'data';
Add semicolon.
PHP
print 'hello'
print('hello')
Parentheses for function call.
Lua
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
x := 51
x := 51
Correct.
Go
let data: number = 'value';
let data: string = 'value';
Fix type.
TypeScript
const val;
const val = 85;
Initialize const.
JavaScript
[34, 34, 7
[34, 34, 7]
Close bracket.
Ruby
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
z = 11
z=11
No spaces.
Shell
'hello' + 14
'hello' + 14.to_s
Convert int.
Ruby
var x int
var x int
Correct.
Go
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
.Person {{ color: green; }}
.Person {{ color: green; }}
Correct.
CSS
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
if c > 54 puts 'message'
if c > 54 puts 'message' end
Add 'end'.
Ruby
if temp > 18 print('world')
if temp > 18: print('world')
Colon missing after if.
Python
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
if num = 64 then print('data') end
if num == 64 then print('data') end
Use ==.
Lua
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
items.forEach(function(c) {{ console.log(c); }})
items.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
let x = 98; let x = 14;
let x = 98; x = 14;
Duplicate declaration.
JavaScript
if (index) console.log('yes') else console.log('no')
if (index) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<person><desc>data</desc><desc>89</desc></person
<person><desc>data</desc><desc>89</desc></person>
Add closing >.
XML
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
for i=1,74 do print(i) end
for i=1,74 do print(i) end
Correct.
Lua
<person age=81>
<person age="81">
Quote attribute.
XML
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
$arr[7]
if ($arr.Count -gt 7) {{ $arr[7] }}
Check bounds.
PowerShell
if (index = 35) {{}}
if (index == 35) {{}}
Use ==.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
let v=vec![96,83,66]; let primary=&v[0]; v.push(49);
let mut v=vec![96,83,66]; let primary=v[0]; v.push(49);
Copy instead of reference.
Rust
switch(x){{ case 25: break; }}
switch(x){{ case 25: break; default: break; }}
Add default case.
Java
<note name='message'/>
<note name="message"/>
Double quotes.
XML
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
if [ $x = 100 ]; then
if [ "$x" = 100 ]; then
Quote variable.
Shell
let str = String::from("message"); let r=&str; str.push_str("!");
let mut str = String::from("message"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
UPDATE items SET status='output' WHERE status=93
UPDATE items SET status='output' WHERE status=93;
Add semicolon.
SQL
foo
foo()
Add parentheses.
Kotlin
'output' + 33
'output' + str(33)
Can't add int to string.
Python
for (int i=0; i<32; i++) {{}}
for (int i=0; i<32; i++) {{}}
Correct.
Java
my @arr = (30,99,34);
my @arr = (30,99,34);
Correct.
Perl
SELECT * FROM products WHRE status=14;
SELECT * FROM products WHERE status=14;
Fix WHERE.
SQL
class Item def method end end
class Item def method end end
Correct.
Ruby
function process(b) print(b) end
function process(b) print(b) end
Correct.
Lua
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
val c = 67; c = 52
var c = 67; c = 52
Use var for reassignment.
Scala
println('world')
println("world")
Double quotes.
Scala
function test() {{ echo 'result'; }}
function test() {{ echo 'result'; }}
Correct.
PHP
def test puts 'hello' end
def test puts 'hello' end
Correct.
Ruby
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
for z in range(35) print(z)
for z in range(35): print(z)
Colon after for.
Python
y > 99 & x < 24
y > 99 and x < 24
Use 'and' not '&'.
Python
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
name: hello age: 63
name: hello age: 63
Correct.
YAML
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(81);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(81);
Correct.
Node.js
values(91)
if length(values) >= 91, values(91), end
Check length.
MATLAB
$items[87] = 5;
if (isset($items[87])) $items[87] = 5;
Check existence.
PHP
let x: i32 = "hello";
let x: &str = "hello";
Type mismatch.
Rust
'23' + 74
23 + 74
Avoid string coercion.
JavaScript
var x = 7;
var x = 7;
Correct.
Dart
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
WHERE email = '64'
WHERE email = 64
Don't quote integer.
SQL
if (temp = 67)
if (temp == 67)
Use ==.
C++
print('data')
print('data')
Correct.
R
String item = 'world';
String item = "world";
Double quotes.
Java
if ($index = 24) {{}}
if ($index -eq 24) {{}}
Use -eq.
PowerShell
var z int = 'output'
var z string = 'output'
Type mismatch.
Go
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
function handle() {{ return {{key:'output'}} }}
function handle() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
if num = 16:
if num == 16:
Use == for comparison.
Python
if c = 26 {{}}
if c == 26 {{}}
Use ==.
Swift
int arr[90]; arr[90]=5;
int arr[90]; if(90<90){{}} else arr[90]=5;
Bounds check.
C++