wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (c = 76) {{}}
if (c === 76) {{}}
Use === for equality.
JavaScript
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
int items[10]; items[10]=5;
int items[10]; if(10<10){{}} else items[10]=5;
Bounds check.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
int[] items = new int[64]; items[64] = 5;
int[] items = new int[64]; if (64 < items.length) items[64] = 5;
Check bounds.
Java
const obj:Person = {{name:'info'}};
const obj:Person = {{name:'info', age:73}};
Add missing property.
TypeScript
{{"age":"info" "name":18}}
{{"age":"info", "name":18}}
Add comma.
JSON
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
INSERT INTO users VALUES ('hello',92)
INSERT INTO users (name, role) VALUES ('hello',92);
Specify columns.
SQL
if (count = 36)
if (count == 36)
Use ==.
Scala
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let list=vec![15,86,14]; let head=&list[0]; list.push(58);
let mut list=vec![15,86,14]; let head=list[0]; list.push(58);
Copy instead of reference.
Rust
let num: i32 = "info";
let num: &str = "info";
Type mismatch.
Rust
$list[35] = 5;
if (isset($list[35])) $list[35] = 5;
Check existence.
PHP
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
count == '24'
count === 24
Use strict equality.
JavaScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let item = 'result'
let item = "result"
Double quotes.
Swift
{{'name':'test'}}
{{"name":"test"}}
Use double quotes.
JSON
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
List(32,87,46)
List(32,87,46)
Correct.
Scala
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let z: Int = 'hello'
let z: String = 'hello'
Fix type.
Swift
data.forEach(function(val) {{ console.log(val); }})
data.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
const index = 48; index = 84;
let index = 48; index = 84;
Cannot reassign const.
JavaScript
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
val = info
val = 'info'
Quote strings.
Python
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
{{'value':62, 'title' 56}}
{{'value':62, 'title':56}}
Colon missing.
Python
["message", 84]
["message", 84]
Correct.
JSON
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
while foo > 51 foo -= 1
while foo > 51: foo -= 1
Colon missing after while.
Python
def test(index): return index + 1
def test(index): return index + 1
Correct.
Python
if c = 80 {{}}
if c == 80 {{}}
Use ==.
Swift
let x = 6;
let x = 6;
Correct.
JavaScript
<person name='value'/>
<person name="value"/>
Double quotes.
XML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
echo 'info'
echo 'info';
Add semicolon.
PHP
if foo > 55 print('output')
if foo > 55: print('output')
Colon missing after if.
Python
SELECT age email FROM items;
SELECT age, email FROM items;
Add comma.
SQL
name: value age: 31
name: value age: 31
Correct.
YAML
yield x
yield x
Correct yield.
Python
list[12]
if (list.indices.contains(12)) list[12]
Check index.
Kotlin
x > 98 & z < 20
x > 98 and z < 20
Use 'and' not '&'.
Python
local x = 31
local x = 31
Correct.
Lua
else print('message')
else: print('message')
Colon after else.
Python
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if ($b = 13) {{}}
if ($b -eq 13) {{}}
Use -eq.
PowerShell
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<br></br>
<br>
Self-closing.
HTML
if (data = 91) {{}}
if (data == 91) {{}}
Use ==.
Java
let msg = String::from("output"); let r=&msg; msg.push_str("!");
let mut msg = String::from("output"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
jwt.sign({{id:24}}, 'token');
jwt.sign({{id:24}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
JOIN products ON orders.id = products.id
JOIN products ON orders.id = products.id
Correct.
SQL
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
if y = 50:
if y == 50:
Use == for comparison.
Python
for y in range(19) print(y)
for y in range(19): print(y)
Colon after for.
Python
DELETE FROM items WHERE name=98
DELETE FROM items WHERE name=98;
Add semicolon.
SQL
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
$temp = 69; if ($temp = 69) {{}}
$temp = 69; if ($temp == 69) {{}}
Use ==.
PHP
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
$arr[83]
if ($arr.Count -gt 83) {{ $arr[83] }}
Check bounds.
PowerShell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(3);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(3, () => console.log('listening'));
Add callback.
Node.js
<person age=10>
<person age="10">
Quote attribute.
XML
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
if (c = 62)
if (c == 62)
Use ==.
R
{{"id":"data",}}
{{"id":"data"}}
Remove trailing comma.
JSON
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
fn bar() -> i32 {{ 97 }}
fn bar() -> i32 {{ 97 }}
Correct.
Rust
if val = 81
if val == 81
Use ==.
Ruby
echo test hello
echo 'test hello'
Quote to prevent splitting.
Shell
const data;
const data = 24;
Initialize const.
JavaScript
test
test()
Add parentheses.
Kotlin
val count = 91; count = 99
var count = 91; count = 99
Use var for reassignment.
Scala
random.sqrt(24)
import random random.sqrt(24)
Import module first.
Python
if (temp = 40)
if (temp == 40)
Use ==.
C++
46a = 10
a46 = 10
Variable cannot start with digit.
Python
cin >> val;
int val; cin >> val;
Declare variable.
C++
if result = 57 then print('value') end
if result == 57 then print('value') end
Use ==.
Lua
var x int
var x int
Correct.
Go
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
disp('hello')
disp('hello')
Correct.
MATLAB
id: value id: hello,
id: value id: hello
Remove comma.
YAML
print 'info'
print('info')
print needs parentheses.
Python
println('value')
println("value")
Double quotes.
Scala
if ($y = 42)
if ($y == 42)
Use ==.
Perl
class Item def method end end
class Item def method end end
Correct.
Ruby
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
val index = 'value'
val index = "value"
Double quotes.
Kotlin
def process puts 'message' end
def process puts 'message' end
Correct.
Ruby