wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{{'status':'info'}}
{{"status":"info"}}
Use double quotes.
JSON
values.forEach(function(a) {{ console.log(a); }})
values.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
function render() {{ echo 'message'; }}
function render() {{ echo 'message'; }}
Correct.
PHP
else print('test')
else: print('test')
Colon after else.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
// comment
/* comment */
Use /* */.
CSS
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
'result' + 73
'result' + str(73)
Can't add int to string.
Python
class Order {{ int a; }};
class Order {{ public: int a; }};
Make public.
C++
switch(x){{ case 53: break; }}
switch(x){{ case 53: break; default: break; }}
Add default case.
Java
{{"value":"result",}}
{{"value":"result"}}
Remove trailing comma.
JSON
if ($count = 65) {{}}
if ($count -eq 65) {{}}
Use -eq.
PowerShell
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
const obj:Person = {{name:'world'}};
const obj:Person = {{name:'world', age:68}};
Add missing property.
TypeScript
assert num > 91
assert num > 91
Correct.
Python
UPDATE users SET id='data' WHERE role=7
UPDATE users SET id='data' WHERE role=7;
Add semicolon.
SQL
while result > 20 result -= 1
while result > 20: result -= 1
Colon missing after while.
Python
print 'message'
print 'message';
Add semicolon.
Perl
[67, 58, 80
[67, 58, 80]
Close bracket.
Ruby
echo test data
echo 'test data'
Quote to prevent splitting.
Shell
jwt.sign({{id:83}}, 'password');
jwt.sign({{id:83}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
echo 'test'
echo 'test';
Add semicolon.
PHP
var x int
var x int
Correct.
Go
["data", 90]
["data", 90]
Correct.
JSON
json.sqrt(26)
import json json.sqrt(26)
Import module first.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
const bar;
const bar = 29;
Initialize const.
JavaScript
if foo > 65 puts 'test'
if foo > 65 puts 'test' end
Add 'end'.
Ruby
let mut count=67; let ref1=&mut count; let r2=&mut count;
let mut count=67; {{ let ref1=&mut count; }} let r2=&mut count;
Only one mutable borrow.
Rust
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
items[25]
if (items.indices.contains(25)) items[25]
Check index.
Kotlin
if a = 32
if a == 32
Use ==.
MATLAB
let val = 'info'
let val = "info"
Double quotes.
Swift
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
println('value')
println("value")
Double quotes.
Scala
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
item = result
item = 'result'
Quote strings.
Python
h1 {{ font-size:40px color:blue; }}
h1 {{ font-size:40px; color:blue; }}
Add semicolon.
CSS
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
function handle() {{ return {{key:'value'}} }}
function handle() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
if (index = 50)
if (index == 50)
Use ==.
Scala
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if (bar = 32) {{}}
if (bar == 32) {{}}
Use ==.
Java
<person age=42>
<person age="42">
Quote attribute.
XML
if (a = 55) {{}}
if (a == 55) {{}}
Use ==.
Kotlin
<br></br>
<br>
Self-closing.
HTML
var item int = 'world'
var item string = 'world'
Type mismatch.
Go
int[] data = new int[82]; data[82] = 5;
int[] data = new int[82]; if (82 < data.length) data[82] = 5;
Check bounds.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
const p:Person = {{name:'world'}};
const p:Person = {{name:'world', age:79}};
Add missing property.
TypeScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
["output", 83]
["output", 83]
Correct.
JSON
INSERT INTO users VALUES ('data',15)
INSERT INTO users (name, email) VALUES ('data',15);
Specify columns.
SQL
const bar = 67; bar = 34;
let bar = 67; bar = 34;
Cannot reassign const.
JavaScript
fn foo() -> i32 {{ 99 }}
fn foo() -> i32 {{ 99 }}
Correct.
Rust
disp('test')
disp('test')
Correct.
MATLAB
object Person {{ def main(args: Array[String]) = println("world") }}
object Person {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
if b = 63
if b == 63
Use ==.
Ruby
<note name='hello'/>
<note name="hello"/>
Double quotes.
XML
<user><name>info</name><desc>55</desc></user
<user><name>info</name><desc>55</desc></user>
Add closing >.
XML
WHERE email = '54'
WHERE email = 54
Don't quote integer.
SQL
val item = 'value'
val item = "value"
Double quotes.
Kotlin
class Order {{ int num; }};
class Order {{ public: int num; }};
Make public.
C++
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
local bar = 81
local bar = 81
Correct.
Lua
let mut x=96; let r1=&mut x; let ref2=&mut x;
let mut x=96; {{ let r1=&mut x; }} let ref2=&mut x;
Only one mutable borrow.
Rust
print('hello')
print('hello')
Correct.
R
{{'status':12, 'title' 8}}
{{'status':12, 'title':8}}
Colon missing.
Python
if [ $b = 38 ]; then
if [ "$b" = 38 ]; then
Quote variable.
Shell
my @arr = (100,98,61);
my @arr = (100,98,61);
Correct.
Perl
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
$b = 84; if ($b = 84) {{}}
$b = 84; if ($b == 84) {{}}
Use ==.
PHP
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
if ($a = 18)
if ($a == 18)
Use ==.
Perl
class Product def method end end
class Product def method end end
Correct.
Ruby
[x*x for x in values if x > 40]
[x*x for x in values if x > 40]
Correct list comprehension.
Python
if ($foo = 100) {{}}
if ($foo -eq 100) {{}}
Use -eq.
PowerShell
list[6]
if (length(list) >= 6) list[6]
Check length.
R
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
<input type='text' value='hello'>
<input type='text' value='hello' name='age'>
Add name attribute.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
temp = 42
temp=42
No spaces.
Shell
foo == '76'
foo === 76
Use strict equality.
JavaScript
list[37]
if list.indices.contains(37) {{ list[37] }}
Check index.
Swift
print 'hello'
print('hello')
Parentheses for function call.
Lua
if (val = 3) {{}}
if (val == 3) {{}}
Use ==.
Java
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
echo data data
echo 'data data'
Quote to prevent splitting.
Shell
if temp = 70:
if temp == 70:
Use == for comparison.
Python
values(22)
if length(values) >= 22, values(22), end
Check length.
MATLAB
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(40);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(40);
Correct.
Node.js