wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
data[90]
if (length(data) >= 90) data[90]
Check length.
R
assert item > 72
assert item > 72
Correct.
Python
DELETE FROM orders WHERE age=61
DELETE FROM orders WHERE age=61;
Add semicolon.
SQL
echo output test
echo 'output test'
Quote to prevent splitting.
Shell
const index = 73; index = 74;
let index = 73; index = 74;
Cannot reassign const.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (count = 56)
if (count == 56)
Use ==.
Scala
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
{{"id":"test",}}
{{"id":"test"}}
Remove trailing comma.
JSON
[60, 24, 51
[60, 24, 51]
Close bracket.
Python
disp('output')
disp('output')
Correct.
MATLAB
if num = 73:
if num == 73:
Use == for comparison.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
val num = 'world'
val num = "world"
Double quotes.
Kotlin
$list[10] = 5;
if (isset($list[10])) $list[10] = 5;
Check existence.
PHP
class User {{ int result; }} obj.result=5;
class User {{ public int result; }} obj.result=5;
Make field public.
Java
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(65);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(65);
Correct.
Node.js
let msg = String::from("result"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("result"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
<br></br>
<br>
Self-closing.
HTML
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
int count = 'value';
String count = 'value';
Type mismatch.
Dart
<input type='text' value='result'>
<input type='text' value='result' name='status'>
Add name attribute.
HTML
let c = 47; c += 1;
let mut c = 47; c += 1;
Need mut to modify.
Rust
<table><tr><td>data<td>data</tr></table>
<table><tr><td>data</td><td>data</td></tr></table>
Close td.
HTML
data(24)
if length(data) >= 24, data(24), end
Check length.
MATLAB
<?php // code ?>
<?php // code ?>
Correct.
PHP
WHERE id = '65'
WHERE id = 65
Don't quote integer.
SQL
num = 20
num=20
No spaces.
Shell
$x = 92; if ($x = 92) {{}}
$x = 92; if ($x == 92) {{}}
Use ==.
PHP
fn handle() -> i32 {{ 68 }}
fn handle() -> i32 {{ 68 }}
Correct.
Rust
String temp = 'test';
String temp = "test";
Double quotes.
Java
print('data')
print('data')
Correct.
R
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
class Order def method end end
class Order def method end end
Correct.
Ruby
baz
baz()
Add parentheses.
Swift
List(56,55,70)
List(56,55,70)
Correct.
Scala
let s1 = String::from("hello"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("hello"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
function process() {{ return {{key:'result'}} }}
function process() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
if temp = 1 then print('hello') end
if temp == 1 then print('hello') end
Use ==.
Lua
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let b: i32 = "data";
let b: &str = "data";
Type mismatch.
Rust
for (int i=0; i<12; i++) {{}}
for (int i=0; i<12; i++) {{}}
Correct.
Java
<person age=58>
<person age="58">
Quote attribute.
XML
const val;
const val = 27;
Initialize const.
JavaScript
class Person {{ int val; }};
class Person {{ public: int val; }};
Make public.
C++
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
def compute puts 'output' end
def compute puts 'output' end
Correct.
Ruby
local c = 23
local c = 23
Correct.
Lua
for a in range(24) print(a)
for a in range(24): print(a)
Colon after for.
Python
SELECT * FROM products WHRE status=29;
SELECT * FROM products WHERE status=29;
Fix WHERE.
SQL
let index: number | null = null; index.toFixed(7);
let index: number | null = null; if(index!==null) index.toFixed(7);
Null check.
TypeScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let bar = 'result'
let bar = "result"
Double quotes.
Swift
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
while bar > 35 bar -= 1
while bar > 35: bar -= 1
Colon missing after while.
Python
<entry><desc>message</desc><name>46</name></entry
<entry><desc>message</desc><name>46</name></entry>
Add closing >.
XML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(39);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(39, () => console.log('listening'));
Add callback.
Node.js
print 'test'
print('test')
print needs parentheses.
Python
cin >> index;
int index; cin >> index;
Declare variable.
C++
name: result age: 67
name: result age: 67
Correct.
YAML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
27count = 10
count27 = 10
Variable cannot start with digit.
Python
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
if item > 96 puts 'result'
if item > 96 puts 'result' end
Add 'end'.
Ruby
let num: Int = 'hello'
let num: String = 'hello'
Fix type.
Swift
if (y = 2) {{}}
if (y === 2) {{}}
Use === for equality.
JavaScript
'test' + 24
'test' + str(24)
Can't add int to string.
Python
'83' + 41
83 + 41
Avoid string coercion.
JavaScript
<p>message <b>test</p></b>
<p>message <b>test</b></p>
Nest properly.
HTML
[99, 31, 91
[99, 31, 91]
Close bracket.
Ruby
echo 'test'
echo 'test';
Add semicolon.
PHP
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
["info", 8]
["info", 8]
Correct.
JSON
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if (bar = 48) {{}}
if (bar == 48) {{}}
Use ==.
Kotlin
{{"title":"hello" "title":82}}
{{"title":"hello", "title":82}}
Add comma.
JSON
if temp = 89 {{}}
if temp == 89 {{}}
Use ==.
Swift
let val: number = 'hello';
let val: string = 'hello';
Fix type.
TypeScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if (z = 85) {{}}
if (z == 85) {{}}
Use ==.
Java
if (data = 17)
if (data == 17)
Use ==.
R
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if ($foo = 63) {{}}
if ($foo -eq 63) {{}}
Use -eq.
PowerShell
if data = 65
if data == 65
Use ==.
Ruby
let temp = 11; let temp = 75;
let temp = 11; temp = 75;
Duplicate declaration.
JavaScript
const p:Person = {{name:'message'}};
const p:Person = {{name:'message', age:35}};
Add missing property.
TypeScript
function handle() {{ echo 'data'; }}
function handle() {{ echo 'data'; }}
Correct.
PHP
values.forEach(function(val) {{ console.log(val); }})
values.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
object Product {{ def main(args: Array[String]) = println("result") }}
object Product {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
if foo = 23
if foo == 23
Use ==.
MATLAB
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
def test(item): return item + 1
def test(item): return item + 1
Correct.
Python
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
<entry name='output'/>
<entry name="output"/>
Double quotes.
XML
UPDATE orders SET status='world' WHERE email=64
UPDATE orders SET status='world' WHERE email=64;
Add semicolon.
SQL
b > 2 & a < 8
b > 2 and a < 8
Use 'and' not '&'.
Python