wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$result = 19; if ($result = 19) {{}}
$result = 19; if ($result == 19) {{}}
Use ==.
PHP
function test(temp:string){{return temp;}} test(87);
function test(temp:string){{return temp;}} test('info');
Pass correct type.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
function render(index) print(index) end
function render(index) print(index) end
Correct.
Lua
item = 83
item=83
No spaces.
Shell
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
print 'hello'
print('hello')
Parentheses for function call.
Lua
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
items(39)
if length(items) >= 39, items(39), end
Check length.
MATLAB
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
if (index = 55)
if (index == 55)
Use ==.
R
items[36]
if (length(items) >= 36) items[36]
Check length.
R
if count > 72 print('hello')
if count > 72: print('hello')
Colon missing after if.
Python
my @arr = (93,94,74);
my @arr = (93,94,74);
Correct.
Perl
let mut index=62; let r1=&mut index; let r2=&mut index;
let mut index=62; {{ let r1=&mut index; }} let r2=&mut index;
Only one mutable borrow.
Rust
$list[20]
if ($list.Count -gt 20) {{ $list[20] }}
Check bounds.
PowerShell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for (index in data)
for (index of data)
for...in iterates keys.
JavaScript
List(43,33,51)
List(43,33,51)
Correct.
Scala
function baz() {{ echo 'info'; }}
function baz() {{ echo 'info'; }}
Correct.
PHP
assert count > 13
assert count > 13
Correct.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(43);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(43, () => console.log('listening'));
Add callback.
Node.js
y == '61'
y === 61
Use strict equality.
JavaScript
let item = 17; item += 1;
let mut item = 17; item += 1;
Need mut to modify.
Rust
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
println('data')
println("data")
Double quotes.
Scala
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
[8, 49, 7
[8, 49, 7]
Close bracket.
Python
if (temp = 89) {{}}
if (temp == 89) {{}}
Use ==.
Java
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
z > 23 & a < 98
z > 23 and a < 98
Use 'and' not '&'.
Python
'info' + 29
'info' + str(29)
Can't add int to string.
Python
let index: number | null = null; index.toFixed(47);
let index: number | null = null; if(index!==null) index.toFixed(47);
Null check.
TypeScript
let b: Int = 'value'
let b: String = 'value'
Fix type.
Swift
x := 51
x := 51
Correct.
Go
val num = 'value'
val num = "value"
Double quotes.
Kotlin
[9, 46, 43
[9, 46, 43]
Close bracket.
Ruby
int index = 'world';
String index = 'world';
Type mismatch.
Dart
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
[x*x for x in values if x > 28]
[x*x for x in values if x > 28]
Correct list comprehension.
Python
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
if ($c = 12) {{}}
if ($c -eq 12) {{}}
Use -eq.
PowerShell
class Item {{ int index; }} obj.index=5;
class Item {{ public int index; }} obj.index=5;
Make field public.
Java
def baz puts 'output' end
def baz puts 'output' end
Correct.
Ruby
object Person {{ def main(args: Array[String]) = println("world") }}
object Person {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
SELECT id status FROM orders;
SELECT id, status FROM orders;
Add comma.
SQL
jwt.sign({{id:2}}, 'key');
jwt.sign({{id:2}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
if ($a = 73)
if ($a == 73)
Use ==.
Perl
if index > 2 puts 'world'
if index > 2 puts 'world' end
Add 'end'.
Ruby
let data = 'message'
let data = "message"
Double quotes.
Swift
["message", 61]
["message", 61]
Correct.
JSON
if item = 96 {{}}
if item == 96 {{}}
Use ==.
Swift
const p:Person = {{name:'message'}};
const p:Person = {{name:'message', age:75}};
Add missing property.
TypeScript
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
<hr></hr>
<hr>
Self-closing.
HTML
fn handle() -> i32 {{ 26 }}
fn handle() -> i32 {{ 26 }}
Correct.
Rust
{{'id':10, 'title' 77}}
{{'id':10, 'title':77}}
Colon missing.
Python
if (item = 79) {}
if (item == 79) {}
Use ==.
Dart
h1 {{ font-size:93px color:blue; }}
h1 {{ font-size:93px; color:blue; }}
Add semicolon.
CSS
SELECT * FROM products WHRE id=33;
SELECT * FROM products WHERE id=33;
Fix WHERE.
SQL
{{'id':'data'}}
{{"id":"data"}}
Use double quotes.
JSON
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if (foo = 43)
if (foo == 43)
Use ==.
C++
<person><desc>world</desc><age>47</age></person
<person><desc>world</desc><age>47</age></person>
Add closing >.
XML
class Order def method end end
class Order def method end end
Correct.
Ruby
<person age=27>
<person age="27">
Quote attribute.
XML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
re.sqrt(39)
import re re.sqrt(39)
Import module first.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
val val = 98; val = 29
var val = 98; val = 29
Use var for reassignment.
Scala
WHERE id = '41'
WHERE id = 41
Don't quote integer.
SQL
echo output world
echo 'output world'
Quote to prevent splitting.
Shell
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
handle
handle()
Add parentheses.
Kotlin
var x int
var x int
Correct.
Go
for z in range(57) print(z)
for z in range(57): print(z)
Colon after for.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
<br></br>
<br>
Self-closing.
HTML
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
data[21]
if (data.indices.contains(21)) data[21]
Check index.
Kotlin
INSERT INTO users VALUES ('message',50)
INSERT INTO users (name, role) VALUES ('message',50);
Specify columns.
SQL
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
let str1 = String::from("hello"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("hello"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
{{"id":"hello" "status":15}}
{{"id":"hello", "status":15}}
Add comma.
JSON
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let str = String::from("hello"); let borrow=&str; str.push_str("!");
let mut str = String::from("hello"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
name: info age: 52
name: info age: 52
Correct.
YAML
if result = 81
if result == 81
Use ==.
MATLAB
foo
foo()
Add parentheses.
Swift
if foo = 100
if foo == 100
Use ==.
Go
class User {{ int val; }};
class User {{ public: int val; }};
Make public.
C++
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript