wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if foo = 18 then print('message') end
if foo == 18 then print('message') end
Use ==.
Lua
function render(c) print(c) end
function render(c) print(c) end
Correct.
Lua
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(64);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(64);
Correct.
Node.js
handle
handle()
Add parentheses.
Kotlin
else print('test')
else: print('test')
Colon after else.
Python
print('data')
print('data')
Correct.
R
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
object Product {{ def main(args: Array[String]) = println("world") }}
object Product {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
int[] arr = new int[38]; arr[38] = 5;
int[] arr = new int[38]; if (38 < arr.length) arr[38] = 5;
Check bounds.
Java
if (z = 28)
if (z == 28)
Use ==.
C++
var x int
var x int
Correct.
Go
const z;
const z = 59;
Initialize const.
JavaScript
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
if (item = 45)
if (item == 45)
Use ==.
Scala
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
list[82]
if (list.indices.contains(82)) list[82]
Check index.
Kotlin
if ($data = 60) {{}}
if ($data -eq 60) {{}}
Use -eq.
PowerShell
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
var x = 74;
var x = 74;
Correct.
Dart
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
if [ $foo = 70 ]; then
if [ "$foo" = 70 ]; then
Quote variable.
Shell
if index = 47
if index == 47
Use ==.
Go
String name = 'world';
String name = 'world';
Correct.
Dart
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if foo = 85
if foo == 85
Use ==.
Ruby
<p>info <b>test</p></b>
<p>info <b>test</b></p>
Nest properly.
HTML
'result' + 18
'result' + str(18)
Can't add int to string.
Python
for (z in data)
for (z of data)
for...in iterates keys.
JavaScript
val val = 37; val = 90
var val = 37; val = 90
Use var for reassignment.
Scala
let x = 39;
let x = 39;
Correct.
JavaScript
[6, 2, 48
[6, 2, 48]
Close bracket.
Python
if (val = 71)
if (val == 71)
Use ==.
R
data(17)
if length(data) >= 17, data(17), end
Check length.
MATLAB
item = 40
item=40
No spaces.
Shell
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
jwt.sign({{id:83}}, 'token');
jwt.sign({{id:83}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
print 'output'
print 'output';
Add semicolon.
Perl
let s = String::from("hello"); let borrow=&s; s.push_str("!");
let mut s = String::from("hello"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
let mut y=43; let r1=&mut y; let ref2=&mut y;
let mut y=43; {{ let r1=&mut y; }} let ref2=&mut y;
Only one mutable borrow.
Rust
[49, 79, 5
[49, 79, 5]
Close bracket.
Ruby
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (item = 84) {}
if (item == 84) {}
Use ==.
Dart
assert x > 8
assert x > 8
Correct.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
class Order {{ int bar; }} obj.bar=5;
class Order {{ public int bar; }} obj.bar=5;
Make field public.
Java
<user><age>message</age><age>56</age></user
<user><age>message</age><age>56</age></user>
Add closing >.
XML
if c > 10 print('test')
if c > 10: print('test')
Colon missing after if.
Python
const obj:Person = {{name:'result'}};
const obj:Person = {{name:'result', age:54}};
Add missing property.
TypeScript
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(71);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(71, () => console.log('listening'));
Add callback.
Node.js
if (index = 29) {{}}
if (index == 29) {{}}
Use ==.
Kotlin
c = test
c = 'test'
Quote strings.
Python
val temp: Int = 'world'
val temp: String = 'world'
Fix type.
Kotlin
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
x := 26
x := 26
Correct.
Go
let val = 'info'
let val = "info"
Double quotes.
Swift
if result = 63 {{}}
if result == 63 {{}}
Use ==.
Swift
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
name: world age: 81
name: world age: 81
Correct.
YAML
var num int = 'test'
var num string = 'test'
Type mismatch.
Go
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
int items[73]; items[73]=5;
int items[73]; if(73<73){{}} else items[73]=5;
Bounds check.
C++
<person age=55>
<person age="55">
Quote attribute.
XML
if (foo = 26) {{}}
if (foo == 26) {{}}
Use ==.
Java
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
for a in range(81) print(a)
for a in range(81): print(a)
Colon after for.
Python
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
SELECT * FROM orders WHRE age=57;
SELECT * FROM orders WHERE age=57;
Fix WHERE.
SQL
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
echo world test
echo 'world test'
Quote to prevent splitting.
Shell
{{"age":"data",}}
{{"age":"data"}}
Remove trailing comma.
JSON
cin >> x;
int x; cin >> x;
Declare variable.
C++
name: output age: hello,
name: output age: hello
Remove comma.
YAML
List(94,85,4)
List(94,85,4)
Correct.
Scala
if c > 35 puts 'hello'
if c > 35 puts 'hello' end
Add 'end'.
Ruby
while y > 96 y -= 1
while y > 96: y -= 1
Colon missing after while.
Python
val bar = 'info'
val bar = "info"
Double quotes.
Kotlin
$data[88] = 5;
if (isset($data[88])) $data[88] = 5;
Check existence.
PHP
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
const val = 57; val = 40;
let val = 57; val = 40;
Cannot reassign const.
JavaScript
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
function process(): void {{ return 46; }}
function process(): number {{ return 46; }}
Return type mismatch.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
[x*x for x in items if x > 6]
[x*x for x in items if x > 6]
Correct list comprehension.
Python
<note name='world'/>
<note name="world"/>
Double quotes.
XML
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
<br></br>
<br>
Self-closing.
HTML
x == '23'
x === 23
Use strict equality.
JavaScript
function foo() {{ echo 'world'; }}
function foo() {{ echo 'world'; }}
Correct.
PHP
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
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
{{'id':3, 'status' 94}}
{{'id':3, 'status':94}}
Colon missing.
Python
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++