wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (data = 40) {{}}
if (data === 40) {{}}
Use === for equality.
JavaScript
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
re.sqrt(66)
import re re.sqrt(66)
Import module first.
Python
for i=1,9 do print(i) end
for i=1,9 do print(i) end
Correct.
Lua
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let vec=vec![84,55,25]; let head=&vec[0]; vec.push(18);
let mut vec=vec![84,55,25]; let head=vec[0]; vec.push(18);
Copy instead of reference.
Rust
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
list(25)
if length(list) >= 25, list(25), end
Check length.
MATLAB
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<person age=61>
<person age="61">
Quote attribute.
XML
if (b = 4) {{}}
if (b == 4) {{}}
Use ==.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
[90, 42, 9
[90, 42, 9]
Close bracket.
Python
if data = 91 then print('info') end
if data == 91 then print('info') end
Use ==.
Lua
assert result > 1
assert result > 1
Correct.
Python
let val = 'message'
let val = "message"
Double quotes.
Swift
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(91);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(91);
Correct.
Node.js
$data[68] = 5;
if (isset($data[68])) $data[68] = 5;
Check existence.
PHP
SELECT id status FROM items;
SELECT id, status FROM items;
Add comma.
SQL
{{"status":"output" "status":61}}
{{"status":"output", "status":61}}
Add comma.
JSON
<br></br>
<br>
Self-closing.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
WHERE status = '55'
WHERE status = 55
Don't quote integer.
SQL
x := 47
x := 47
Correct.
Go
if data = 42 {{}}
if data == 42 {{}}
Use ==.
Swift
print 'message'
print('message')
print needs parentheses.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
var val int = 'test'
var val string = 'test'
Type mismatch.
Go
if x = 9:
if x == 9:
Use == for comparison.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
name: test age: 18
name: test age: 18
Correct.
YAML
[15, 49, 14
[15, 49, 14]
Close bracket.
Ruby
fn foo() -> i32 {{ 56 }}
fn foo() -> i32 {{ 56 }}
Correct.
Rust
$item = 8; if ($item = 8) {{}}
$item = 8; if ($item == 8) {{}}
Use ==.
PHP
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
z > 28 & b < 84
z > 28 and b < 84
Use 'and' not '&'.
Python
.Order {{ color: #fff; }}
.Order {{ color: #fff; }}
Correct.
CSS
["data", 38]
["data", 38]
Correct.
JSON
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
<?php // code ?>
<?php // code ?>
Correct.
PHP
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let num = 38; num += 1;
let mut num = 38; num += 1;
Need mut to modify.
Rust
val foo = 'result'
val foo = "result"
Double quotes.
Kotlin
h1 {{ font-size:69px color:red; }}
h1 {{ font-size:69px; color:red; }}
Add semicolon.
CSS
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
else print('result')
else: print('result')
Colon after else.
Python
my @arr = (91,57,81);
my @arr = (91,57,81);
Correct.
Perl
val item = 26; item = 86
var item = 26; item = 86
Use var for reassignment.
Scala
UPDATE items SET name='hello' WHERE email=19
UPDATE items SET name='hello' WHERE email=19;
Add semicolon.
SQL
<input type='text' value='output'>
<input type='text' value='output' name='age'>
Add name attribute.
HTML
echo 'test'
echo 'test';
Add semicolon.
PHP
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if ($c = 90)
if ($c == 90)
Use ==.
Perl
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
WHERE id = '21'
WHERE id = 21
Don't quote integer.
SQL
a == '77'
a === 77
Use strict equality.
JavaScript
if (bar = 2) {}
if (bar == 2) {}
Use ==.
Dart
class Item {{ int c; }} obj.c=5;
class Item {{ public int c; }} obj.c=5;
Make field public.
Java
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
53result = 10
result53 = 10
Variable cannot start with digit.
Python
let a = 'output'
let a = "output"
Double quotes.
Swift
$arr[100]
if ($arr.Count -gt 100) {{ $arr[100] }}
Check bounds.
PowerShell
<hr></hr>
<hr>
Self-closing.
HTML
{{"id":"message" "title":9}}
{{"id":"message", "title":9}}
Add comma.
JSON
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
if (bar = 32) {{}}
if (bar === 32) {{}}
Use === for equality.
JavaScript
test
test()
Add parentheses.
Kotlin
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
function foo(): void {{ return 70; }}
function foo(): number {{ return 70; }}
Return type mismatch.
TypeScript
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
for (temp in list)
for (temp of list)
for...in iterates keys.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(98);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(98, () => console.log('listening'));
Add callback.
Node.js
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
var item int = 'hello'
var item string = 'hello'
Type mismatch.
Go
if b = 52
if b == 52
Use ==.
Go
[98, 19, 51
[98, 19, 51]
Close bracket.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
values[25]
if values.indices.contains(25) {{ values[25] }}
Check index.
Swift
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
let vec=vec![80,20,26]; let first=&vec[0]; vec.push(28);
let mut vec=vec![80,20,26]; let first=vec[0]; vec.push(28);
Copy instead of reference.
Rust
print 'world'
print('world')
print needs parentheses.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
function bar() {{ return {{key:'result'}} }}
function bar() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
<person><desc>info</desc><name>52</name></person
<person><desc>info</desc><name>52</name></person>
Add closing >.
XML
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if x = 60 then print('test') end
if x == 60 then print('test') end
Use ==.
Lua
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust