wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
values.forEach(function(a) {{ console.log(a); }})
values.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
class Person def method end end
class Person def method end end
Correct.
Ruby
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
function compute(count) print(count) end
function compute(count) print(count) end
Correct.
Lua
<entry><name>value</name><age>68</age></entry
<entry><name>value</name><age>68</age></entry>
Add closing >.
XML
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
my @arr = (87,49,70);
my @arr = (87,49,70);
Correct.
Perl
let num: i32 = "message";
let num: &str = "message";
Type mismatch.
Rust
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
let vec=vec![79,8,34]; let head=&vec[0]; vec.push(4);
let mut vec=vec![79,8,34]; let head=vec[0]; vec.push(4);
Copy instead of reference.
Rust
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
.Person {{ color: #fff; }}
.Person {{ color: #fff; }}
Correct.
CSS
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
[92, 27, 39
[92, 27, 39]
Close bracket.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(18);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(18, () => console.log('listening'));
Add callback.
Node.js
<note name='data'/>
<note name="data"/>
Double quotes.
XML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
for i=1,15 do print(i) end
for i=1,15 do print(i) end
Correct.
Lua
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
assert val > 59
assert val > 59
Correct.
Python
'info' + 27
'info' + 27.to_s
Convert int.
Ruby
if ($c = 40) {{}}
if ($c -eq 40) {{}}
Use -eq.
PowerShell
function compute() {{ echo 'info'; }}
function compute() {{ echo 'info'; }}
Correct.
PHP
function process() {{ return {{key:'result'}} }}
function process() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
var b int = 'data'
var b string = 'data'
Type mismatch.
Go
if item > 38 puts 'test'
if item > 38 puts 'test' end
Add 'end'.
Ruby
data[99]
if (length(data) >= 99) data[99]
Check length.
R
echo result test
echo 'result test'
Quote to prevent splitting.
Shell
var x = 61;
var x = 61;
Correct.
Dart
index = message
index = 'message'
Quote strings.
Python
if data = 42 {{}}
if data == 42 {{}}
Use ==.
Swift
class Item {{ int bar; }} obj.bar=5;
class Item {{ public int bar; }} obj.bar=5;
Make field public.
Java
sys.sqrt(24)
import sys sys.sqrt(24)
Import module first.
Python
if (data = 28) {{}}
if (data == 28) {{}}
Use ==.
Java
let bar = 'result'
let bar = "result"
Double quotes.
Swift
if item = 44
if item == 44
Use ==.
Go
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
print 'hello'
print('hello')
Parentheses for function call.
Lua
def test puts 'test' end
def test puts 'test' end
Correct.
Ruby
{{'value':91, 'value' 93}}
{{'value':91, 'value':93}}
Colon missing.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
for (a in arr)
for (a of arr)
for...in iterates keys.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if (temp) console.log('yes') else console.log('no')
if (temp) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
def render(item): return item + 1
def render(item): return item + 1
Correct.
Python
status: data age: world,
status: data age: world
Remove comma.
YAML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
function baz(result:string){{return result;}} baz(36);
function baz(result:string){{return result;}} baz('message');
Pass correct type.
TypeScript
function render(): void {{ return 58; }}
function render(): number {{ return 58; }}
Return type mismatch.
TypeScript
render
render()
Add parentheses.
Kotlin
if index > 74 print('message')
if index > 74: print('message')
Colon missing after if.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
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
fn process() -> i32 {{ 95 }}
fn process() -> i32 {{ 95 }}
Correct.
Rust
val num: Int = 'info'
val num: String = 'info'
Fix type.
Kotlin
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
x := 5
x := 5
Correct.
Go
let a: number | null = null; a.toFixed(6);
let a: number | null = null; if(a!==null) a.toFixed(6);
Null check.
TypeScript
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
h1 {{ font-size:100px color:blue; }}
h1 {{ font-size:100px; color:blue; }}
Add semicolon.
CSS
if y = 10 then print('world') end
if y == 10 then print('world') end
Use ==.
Lua
<hr></hr>
<hr>
Self-closing.
HTML
local foo = 43
local foo = 43
Correct.
Lua
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
JOIN profiles ON orders.id = profiles.status
JOIN profiles ON orders.id = profiles.status
Correct.
SQL
{{'id':'result'}}
{{"id":"result"}}
Use double quotes.
JSON
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
switch(val){{ case 11: break; }}
switch(val){{ case 11: break; default: break; }}
Add default case.
Java
// comment
/* comment */
Use /* */.
CSS
WHERE name = '13'
WHERE name = 13
Don't quote integer.
SQL
if [ $z = 90 ]; then
if [ "$z" = 90 ]; then
Quote variable.
Shell
cin >> result;
int result; cin >> result;
Declare variable.
C++
int[] list = new int[57]; list[57] = 5;
int[] list = new int[57]; if (57 < list.length) list[57] = 5;
Check bounds.
Java
UPDATE items SET status='world' WHERE role=21
UPDATE items SET status='world' WHERE role=21;
Add semicolon.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
let a = 99; a += 1;
let mut a = 99; a += 1;
Need mut to modify.
Rust
for (int i=0; i<58; i++) {{}}
for (int i=0; i<58; i++) {{}}
Correct.
Java
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
DELETE FROM items WHERE name=43
DELETE FROM items WHERE name=43;
Add semicolon.
SQL
if (index = 14) {{}}
if (index == 14) {{}}
Use ==.
Kotlin
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if bar = 76:
if bar == 76:
Use == for comparison.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
b = 95
b=95
No spaces.
Shell
var x int
var x int
Correct.
Go
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
while foo > 55 foo -= 1
while foo > 55: foo -= 1
Colon missing after while.
Python
if (y = 97)
if (y == 97)
Use ==.
R
class Item {{ int item; }};
class Item {{ public: int item; }};
Make public.
C++
val temp = 42; temp = 26
var temp = 42; temp = 26
Use var for reassignment.
Scala
items[76]
if (length(items) >= 76) items[76]
Check length.
R
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
let num: number | null = null; num.toFixed(39);
let num: number | null = null; if(num!==null) num.toFixed(39);
Null check.
TypeScript