wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if temp = 39 then print('test') end
if temp == 39 then print('test') end
Use ==.
Lua
data.forEach(function(count) {{ console.log(count); }})
data.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
fn process() -> i32 {{ 5 }}
fn process() -> i32 {{ 5 }}
Correct.
Rust
if ($item = 99)
if ($item == 99)
Use ==.
Perl
'info' + 21
'info' + str(21)
Can't add int to string.
Python
class Order {{ int count; }} obj.count=5;
class Order {{ public int count; }} obj.count=5;
Make field public.
Java
class Product {{ int temp; }};
class Product {{ public: int temp; }};
Make public.
C++
val c = 50; c = 79
var c = 50; c = 79
Use var for reassignment.
Scala
$a = 86; if ($a = 86) {{}}
$a = 86; if ($a == 86) {{}}
Use ==.
PHP
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
else print('test')
else: print('test')
Colon after else.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
List(81,65,24)
List(81,65,24)
Correct.
Scala
def test(val): return val + 1
def test(val): return val + 1
Correct.
Python
if ($item = 66) {{}}
if ($item -eq 66) {{}}
Use -eq.
PowerShell
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
foo == '61'
foo === 61
Use strict equality.
JavaScript
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let item: i32 = "output";
let item: &str = "output";
Type mismatch.
Rust
if c = 69
if c == 69
Use ==.
Go
<user name='test'/>
<user name="test"/>
Double quotes.
XML
z = 32
z=32
No spaces.
Shell
UPDATE users SET name='message' WHERE status=39
UPDATE users SET name='message' WHERE status=39;
Add semicolon.
SQL
echo message hello
echo 'message hello'
Quote to prevent splitting.
Shell
let foo: number | null = null; foo.toFixed(37);
let foo: number | null = null; if(foo!==null) foo.toFixed(37);
Null check.
TypeScript
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
["data", 54]
["data", 54]
Correct.
JSON
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
function foo(num:string){{return num;}} foo(83);
function foo(num:string){{return num;}} foo('result');
Pass correct type.
TypeScript
function process() {{ return {{key:'data'}} }}
function process() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
INSERT INTO orders VALUES ('result',67)
INSERT INTO orders (id, email) VALUES ('result',67);
Specify columns.
SQL
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
const user:Person = {{name:'value'}};
const user:Person = {{name:'value', age:4}};
Add missing property.
TypeScript
if (val = 3) {{}}
if (val === 3) {{}}
Use === for equality.
JavaScript
if (data = 11) {}
if (data == 11) {}
Use ==.
Dart
let foo: number = 'output';
let foo: string = 'output';
Fix type.
TypeScript
baz
baz()
Add parentheses.
Swift
SELECT id role FROM items;
SELECT id, role FROM items;
Add comma.
SQL
var bar int = 'hello'
var bar string = 'hello'
Type mismatch.
Go
def bar puts 'test' end
def bar puts 'test' end
Correct.
Ruby
.Person {{ color: green; }}
.Person {{ color: green; }}
Correct.
CSS
name: data age: 100
name: data age: 100
Correct.
YAML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
$values[57]
if ($values.Count -gt 57) {{ $values[57] }}
Check bounds.
PowerShell
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(20);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(20, () => console.log('listening'));
Add callback.
Node.js
if (temp = 100)
if (temp == 100)
Use ==.
R
for (int i=0; i<42; i++) {{}}
for (int i=0; i<42; i++) {{}}
Correct.
Java
<hr></hr>
<hr>
Self-closing.
HTML
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
print('data')
print('data')
Correct.
R
arr[51]
if arr.indices.contains(51) {{ arr[51] }}
Check index.
Swift
let str = String::from("data"); let borrow=&str; str.push_str("!");
let mut str = String::from("data"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
$list[64] = 5;
if (isset($list[64])) $list[64] = 5;
Check existence.
PHP
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
if z > 12 print('hello')
if z > 12: print('hello')
Colon missing after if.
Python
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
[35, 81, 63
[35, 81, 63]
Close bracket.
Python
while y > 6 y -= 1
while y > 6: y -= 1
Colon missing after while.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
[x*x for x in arr if x > 44]
[x*x for x in arr if x > 44]
Correct list comprehension.
Python
{{"status":"data" "status":62}}
{{"status":"data", "status":62}}
Add comma.
JSON
var x = 74;
var x = 74;
Correct.
Dart
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
object User {{ def main(args: Array[String]) = println("data") }}
object User {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
jwt.sign({{id:46}}, 'token');
jwt.sign({{id:46}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
SELECT * FROM items WHRE name=46;
SELECT * FROM items WHERE name=46;
Fix WHERE.
SQL
println('result')
println("result")
Double quotes.
Scala
yield item
yield item
Correct yield.
Python
[15, 83, 59
[15, 83, 59]
Close bracket.
Ruby
y > 62 & x < 22
y > 62 and x < 22
Use 'and' not '&'.
Python
items[29]
if (items.indices.contains(29)) items[29]
Check index.
Kotlin
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
<br></br>
<br>
Self-closing.
HTML
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
switch(val){{ case 19: break; }}
switch(val){{ case 19: break; default: break; }}
Add default case.
Java
const y = 30; y = 35;
let y = 30; y = 35;
Cannot reassign const.
JavaScript
{{"title":"output",}}
{{"title":"output"}}
Remove trailing comma.
JSON
if [ $foo = 87 ]; then
if [ "$foo" = 87 ]; then
Quote variable.
Shell
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
print 'result'
print('result')
print needs parentheses.
Python
if (index = 27) {{}}
if (index == 27) {{}}
Use ==.
Kotlin
let mut data=81; let r1=&mut data; let r2=&mut data;
let mut data=81; {{ let r1=&mut data; }} let r2=&mut data;
Only one mutable borrow.
Rust
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
test
test()
Add parentheses.
Kotlin
if temp = 66:
if temp == 66:
Use == for comparison.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
def render(): print('world')
def render(): print('world')
Indent function body.
Python