wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
3count = 10
count3 = 10
Variable cannot start with digit.
Python
let index: number | null = null; index.toFixed(51);
let index: number | null = null; if(index!==null) index.toFixed(51);
Null check.
TypeScript
<hr></hr>
<hr>
Self-closing.
HTML
function test(): void {{ return 53; }}
function test(): number {{ return 53; }}
Return type mismatch.
TypeScript
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
SELECT * FROM items WHRE age=45;
SELECT * FROM items WHERE age=45;
Fix WHERE.
SQL
if [ $foo = 57 ]; then
if [ "$foo" = 57 ]; then
Quote variable.
Shell
<input type='text' value='value'>
<input type='text' value='value' name='value'>
Add name attribute.
HTML
if ($c = 74) {{}}
if ($c -eq 74) {{}}
Use -eq.
PowerShell
if (count = 73)
if (count == 73)
Use ==.
Scala
while foo > 99 foo -= 1
while foo > 99: foo -= 1
Colon missing after while.
Python
data = test
data = 'test'
Quote strings.
Python
[93, 26, 19
[93, 26, 19]
Close bracket.
Ruby
String y = 'result';
String y = "result";
Double quotes.
Java
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(37);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(37, () => console.log('listening'));
Add callback.
Node.js
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
["data", 8]
["data", 8]
Correct.
JSON
let c: number = 'message';
let c: string = 'message';
Fix type.
TypeScript
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
val b = 53; b = 5
var b = 53; b = 5
Use var for reassignment.
Scala
data.forEach(function(val) {{ console.log(val); }})
data.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
h1 {{ font-size:35px color:red; }}
h1 {{ font-size:35px; color:red; }}
Add semicolon.
CSS
List(54,99,59)
List(54,99,59)
Correct.
Scala
class User {{ int num; }};
class User {{ public: int num; }};
Make public.
C++
let b = 80; b += 1;
let mut b = 80; b += 1;
Need mut to modify.
Rust
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
print 'info'
print 'info';
Add semicolon.
Perl
{{"name":"test",}}
{{"name":"test"}}
Remove trailing comma.
JSON
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(55);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(55);
Correct.
Node.js
String name = 'output';
String name = 'output';
Correct.
Dart
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
[65, 45, 64
[65, 45, 64]
Close bracket.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
int bar = 'info';
String bar = 'info';
Type mismatch.
Dart
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
list(3)
if length(list) >= 3, list(3), end
Check length.
MATLAB
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let a: i32 = "value";
let a: &str = "value";
Type mismatch.
Rust
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
num == '30'
num === 30
Use strict equality.
JavaScript
<br></br>
<br>
Self-closing.
HTML
local index = 17
local index = 17
Correct.
Lua
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
name: output age: 71
name: output age: 71
Correct.
YAML
if foo = 64 then print('hello') end
if foo == 64 then print('hello') end
Use ==.
Lua
if x = 43:
if x == 43:
Use == for comparison.
Python
<p>output <b>test</p></b>
<p>output <b>test</b></p>
Nest properly.
HTML
x := 25
x := 25
Correct.
Go
print 'hello'
print('hello')
print needs parentheses.
Python
val index = 'result'
val index = "result"
Double quotes.
Kotlin
echo 'data'
echo 'data';
Add semicolon.
PHP
for (int i=0; i<97; i++) {{}}
for (int i=0; i<97; i++) {{}}
Correct.
Java
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
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
SELECT name role FROM orders;
SELECT name, role FROM orders;
Add comma.
SQL
class Product {{ int val; }} obj.val=5;
class Product {{ public int val; }} obj.val=5;
Make field public.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
'15' + 28
15 + 28
Avoid string coercion.
JavaScript
else print('value')
else: print('value')
Colon after else.
Python
if (count = 93) {{}}
if (count === 93) {{}}
Use === for equality.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if b = 47
if b == 47
Use ==.
Go
WHERE name = '87'
WHERE name = 87
Don't quote integer.
SQL
data = 30
data=30
No spaces.
Shell
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
$val = 15; if ($val = 15) {{}}
$val = 15; if ($val == 15) {{}}
Use ==.
PHP
let index: Int = 'world'
let index: String = 'world'
Fix type.
Swift
val y: Int = 'output'
val y: String = 'output'
Fix type.
Kotlin
int list[97]; list[97]=5;
int list[97]; if(97<97){{}} else list[97]=5;
Bounds check.
C++
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
class Person def method end end
class Person def method end end
Correct.
Ruby
JOIN profiles ON items.id = profiles.age
JOIN profiles ON items.id = profiles.age
Correct.
SQL
function render() {{ return {{key:'info'}} }}
function render() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
if num > 20 print('output')
if num > 20: print('output')
Colon missing after if.
Python
// comment
/* comment */
Use /* */.
CSS
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
var x = 92;
var x = 92;
Correct.
Dart
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
let a = 78;
let a = 78;
Correct.
JavaScript
int[] arr = new int[64]; arr[64] = 5;
int[] arr = new int[64]; if (64 < arr.length) arr[64] = 5;
Check bounds.
Java
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
{{'name':'data'}}
{{"name":"data"}}
Use double quotes.
JSON
if (item = 33) {{}}
if (item == 33) {{}}
Use ==.
Kotlin
def baz puts 'message' end
def baz puts 'message' end
Correct.
Ruby
yield result
yield result
Correct yield.
Python
function baz(val) print(val) end
function baz(val) print(val) end
Correct.
Lua
def handle(item): return item + 1
def handle(item): return item + 1
Correct.
Python
let foo = 82; let foo = 61;
let foo = 82; foo = 61;
Duplicate declaration.
JavaScript
let count = 'value'
let count = "value"
Double quotes.
Swift
data[28]
if (length(data) >= 28) data[28]
Check length.
R
<person name='result'/>
<person name="result"/>
Double quotes.
XML
fn compute() -> i32 {{ 67 }}
fn compute() -> i32 {{ 67 }}
Correct.
Rust
disp('message')
disp('message')
Correct.
MATLAB