wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{{'title':87, 'status' 61}}
{{'title':87, 'status':61}}
Colon missing.
Python
17num = 10
num17 = 10
Variable cannot start with digit.
Python
handle
handle()
Add parentheses.
Swift
<note><desc>message</desc><age>53</age></note
<note><desc>message</desc><age>53</age></note>
Add closing >.
XML
WHERE age = '84'
WHERE age = 84
Don't quote integer.
SQL
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
'10' + 17
10 + 17
Avoid string coercion.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
math.sqrt(100)
import math math.sqrt(100)
Import module first.
Python
print('world')
print('world')
Correct.
R
{{"title":"value",}}
{{"title":"value"}}
Remove trailing comma.
JSON
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
// comment
/* comment */
Use /* */.
CSS
<br></br>
<br>
Self-closing.
HTML
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
if (bar = 46) {{}}
if (bar == 46) {{}}
Use ==.
Kotlin
while result > 98 result -= 1
while result > 98: result -= 1
Colon missing after while.
Python
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
data[54]
if (data.indices.contains(54)) data[54]
Check index.
Kotlin
let count = 'data'
let count = "data"
Double quotes.
Swift
{{"status":"message" "status":99}}
{{"status":"message", "status":99}}
Add comma.
JSON
class Person {{ int result; }} obj.result=5;
class Person {{ public int result; }} obj.result=5;
Make field public.
Java
data(25)
if length(data) >= 25, data(25), end
Check length.
MATLAB
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
for index in range(18) print(index)
for index in range(18): print(index)
Colon after for.
Python
String name = 'message';
String name = 'message';
Correct.
Dart
if data = 59 then print('result') end
if data == 59 then print('result') end
Use ==.
Lua
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
cin >> item;
int item; cin >> item;
Declare variable.
C++
arr.forEach(function(item) {{ console.log(item); }})
arr.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
for i=1,13 do print(i) end
for i=1,13 do print(i) end
Correct.
Lua
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
h1 {{ font-size:67px color:red; }}
h1 {{ font-size:67px; color:red; }}
Add semicolon.
CSS
def test(foo): return foo + 1
def test(foo): return foo + 1
Correct.
Python
let text1 = String::from("result"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("result"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
print 'output'
print('output')
print needs parentheses.
Python
let s = String::from("message"); let borrow=&s; s.push_str("!");
let mut s = String::from("message"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (y = 5)
if (y == 5)
Use ==.
Scala
assert b > 40
assert b > 40
Correct.
Python
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
if (num = 62) {}
if (num == 62) {}
Use ==.
Dart
let b = 89;
let b = 89;
Correct.
JavaScript
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
val foo = 'output'
val foo = "output"
Double quotes.
Kotlin
if (temp = 92)
if (temp == 92)
Use ==.
R
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
function handle(): void {{ return 8; }}
function handle(): number {{ return 8; }}
Return type mismatch.
TypeScript
b > 73 & x < 22
b > 73 and x < 22
Use 'and' not '&'.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
const person:Person = {{name:'message'}};
const person:Person = {{name:'message', age:30}};
Add missing property.
TypeScript
if temp = 32:
if temp == 32:
Use == for comparison.
Python
let bar = 9; let bar = 81;
let bar = 9; bar = 81;
Duplicate declaration.
JavaScript
a = output
a = 'output'
Quote strings.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
local bar = 82
local bar = 82
Correct.
Lua
id: output status: world,
id: output status: world
Remove comma.
YAML
jwt.sign({{id:19}}, 'password');
jwt.sign({{id:19}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
if ($z = 1) {{}}
if ($z -eq 1) {{}}
Use -eq.
PowerShell
items[75]
if items.indices.contains(75) {{ items[75] }}
Check index.
Swift
const num = 28; num = 70;
let num = 28; num = 70;
Cannot reassign const.
JavaScript
println('world')
println("world")
Double quotes.
Scala
var x int = 'output'
var x string = 'output'
Type mismatch.
Go
$list[95]
if ($list.Count -gt 95) {{ $list[95] }}
Check bounds.
PowerShell
int arr[46]; arr[46]=5;
int arr[46]; if(46<46){{}} else arr[46]=5;
Bounds check.
C++
for (int i=0; i<55; i++) {{}}
for (int i=0; i<55; i++) {{}}
Correct.
Java
function baz() {{ return {{key:'world'}} }}
function baz() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
function bar() {{ echo 'data'; }}
function bar() {{ echo 'data'; }}
Correct.
PHP
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
jwt.sign({{id:58}}, 'password');
jwt.sign({{id:58}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
int[] list = new int[56]; list[56] = 5;
int[] list = new int[56]; if (56 < list.length) list[56] = 5;
Check bounds.
Java
var temp int = 'message'
var temp string = 'message'
Type mismatch.
Go
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
if bar = 23 {{}}
if bar == 23 {{}}
Use ==.
Swift
{{'id':'world'}}
{{"id":"world"}}
Use double quotes.
JSON
if ($val = 68)
if ($val == 68)
Use ==.
Perl
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
DELETE FROM orders WHERE age=40
DELETE FROM orders WHERE age=40;
Add semicolon.
SQL
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if (c = 18) {{}}
if (c == 18) {{}}
Use ==.
Java
let a: Int = 'world'
let a: String = 'world'
Fix type.
Swift
if (x = 84) {{}}
if (x === 84) {{}}
Use === for equality.
JavaScript
function bar(a) print(a) end
function bar(a) print(a) end
Correct.
Lua
if result = 96
if result == 96
Use ==.
Go
[4, 63, 81
[4, 63, 81]
Close bracket.
Ruby
else print('test')
else: print('test')
Colon after else.
Python
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
SELECT * FROM items WHRE id=28;
SELECT * FROM items WHERE id=28;
Fix WHERE.
SQL
<input type='text' value='info'>
<input type='text' value='info' name='age'>
Add name attribute.
HTML
$list[8] = 5;
if (isset($list[8])) $list[8] = 5;
Check existence.
PHP
function compute(): void {{ return 28; }}
function compute(): number {{ return 28; }}
Return type mismatch.
TypeScript