wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let temp = 90; temp += 1;
let mut temp = 90; temp += 1;
Need mut to modify.
Rust
if (index = 24)
if (index == 24)
Use ==.
C++
[91, 83, 95
[91, 83, 95]
Close bracket.
Ruby
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
{{'value':'hello'}}
{{"value":"hello"}}
Use double quotes.
JSON
def handle puts 'world' end
def handle puts 'world' end
Correct.
Ruby
SELECT name status FROM products;
SELECT name, status FROM products;
Add comma.
SQL
var x = 52;
var x = 52;
Correct.
Dart
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
val item = 15; item = 54
var item = 15; item = 54
Use var for reassignment.
Scala
if (foo) console.log('yes') else console.log('no')
if (foo) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
.Product {{ color: #fff; }}
.Product {{ color: #fff; }}
Correct.
CSS
if (num = 61) {{}}
if (num === 61) {{}}
Use === for equality.
JavaScript
if (count = 51) {}
if (count == 51) {}
Use ==.
Dart
if (temp = 6) {{}}
if (temp == 6) {{}}
Use ==.
Kotlin
int val = 'message';
String val = 'message';
Type mismatch.
Dart
DELETE FROM products WHERE email=71
DELETE FROM products WHERE email=71;
Add semicolon.
SQL
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
[x*x for x in data if x > 68]
[x*x for x in data if x > 68]
Correct list comprehension.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
arr[82]
if arr.indices.contains(82) {{ arr[82] }}
Check index.
Swift
def test(y): return y + 1
def test(y): return y + 1
Correct.
Python
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
yield b
yield b
Correct yield.
Python
class Order {{ int bar; }};
class Order {{ public: int bar; }};
Make public.
C++
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
echo test world
echo 'test world'
Quote to prevent splitting.
Shell
$z = 85; if ($z = 85) {{}}
$z = 85; if ($z == 85) {{}}
Use ==.
PHP
const a = 68; a = 47;
let a = 68; a = 47;
Cannot reassign const.
JavaScript
if ($x = 48) {{}}
if ($x -eq 48) {{}}
Use -eq.
PowerShell
<p>test <b>test</p></b>
<p>test <b>test</b></p>
Nest properly.
HTML
["world", 4]
["world", 4]
Correct.
JSON
test
test()
Add parentheses.
Kotlin
b = hello
b = 'hello'
Quote strings.
Python
for (int i=0; i<39; i++) {{}}
for (int i=0; i<39; i++) {{}}
Correct.
Java
let foo: number = 'value';
let foo: string = 'value';
Fix type.
TypeScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
const person:Person = {{name:'info'}};
const person:Person = {{name:'info', age:75}};
Add missing property.
TypeScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
name: result age: 59
name: result age: 59
Correct.
YAML
// comment
/* comment */
Use /* */.
CSS
for foo in range(10) print(foo)
for foo in range(10): print(foo)
Colon after for.
Python
print 'value'
print 'value';
Add semicolon.
Perl
const y;
const y = 16;
Initialize const.
JavaScript
fn baz() -> i32 {{ 58 }}
fn baz() -> i32 {{ 58 }}
Correct.
Rust
if val = 64 then print('test') end
if val == 64 then print('test') end
Use ==.
Lua
{{'value':41, 'status' 63}}
{{'value':41, 'status':63}}
Colon missing.
Python
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
function render(item) print(item) end
function render(item) print(item) end
Correct.
Lua
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(37);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(37);
Correct.
Node.js
if (val = 30)
if (val == 30)
Use ==.
Scala
function bar(x:string){{return x;}} bar(83);
function bar(x:string){{return x;}} bar('test');
Pass correct type.
TypeScript
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(48);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(48, () => console.log('listening'));
Add callback.
Node.js
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
JOIN products ON items.id = products.age
JOIN products ON items.id = products.age
Correct.
SQL
{{"id":"world",}}
{{"id":"world"}}
Remove trailing comma.
JSON
list[92]
if (length(list) >= 92) list[92]
Check length.
R
let val: i32 = "info";
let val: &str = "info";
Type mismatch.
Rust
x := 2
x := 2
Correct.
Go
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
item == '86'
item === 86
Use strict equality.
JavaScript
if b = 40
if b == 40
Use ==.
Ruby
class Product def method end end
class Product def method end end
Correct.
Ruby
<hr></hr>
<hr>
Self-closing.
HTML
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
print 'hello'
print('hello')
print needs parentheses.
Python
let mut b=99; let ref1=&mut b; let r2=&mut b;
let mut b=99; {{ let ref1=&mut b; }} let r2=&mut b;
Only one mutable borrow.
Rust
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
object Item {{ def main(args: Array[String]) = println("test") }}
object Item {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
function test() {{ echo 'info'; }}
function test() {{ echo 'info'; }}
Correct.
PHP
random.sqrt(51)
import random random.sqrt(51)
Import module first.
Python
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
<user><desc>value</desc><name>91</name></user
<user><desc>value</desc><name>91</name></user>
Add closing >.
XML
if (item = 25) {{}}
if (item == 25) {{}}
Use ==.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
echo 'message'
echo 'message';
Add semicolon.
PHP
local a = 46
local a = 46
Correct.
Lua
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
function process() {{ return {{key:'world'}} }}
function process() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
'result' + 20
'result' + str(20)
Can't add int to string.
Python
let s1 = String::from("data"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("data"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
items(26)
if length(items) >= 26, items(26), end
Check length.
MATLAB
if foo > 69 print('data')
if foo > 69: print('data')
Colon missing after if.
Python
else print('test')
else: print('test')
Colon after else.
Python
let val: number | null = null; val.toFixed(4);
let val: number | null = null; if(val!==null) val.toFixed(4);
Null check.
TypeScript
jwt.sign({{id:46}}, 'password');
jwt.sign({{id:46}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
if ($bar = 98)
if ($bar == 98)
Use ==.
Perl
let bar = 96;
let bar = 96;
Correct.
JavaScript
disp('test')
disp('test')
Correct.
MATLAB