wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
values.forEach(function(result) {{ console.log(result); }})
values.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
JOIN orders ON items.id = orders.name
JOIN orders ON items.id = orders.name
Correct.
SQL
def baz(a): return a + 1
def baz(a): return a + 1
Correct.
Python
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(18);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(18);
Correct.
Node.js
print 'result'
print 'result';
Add semicolon.
Perl
var x int
var x int
Correct.
Go
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let bar: number = 'result';
let bar: string = 'result';
Fix type.
TypeScript
$item = 27; if ($item = 27) {{}}
$item = 27; if ($item == 27) {{}}
Use ==.
PHP
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if c = 81
if c == 81
Use ==.
Ruby
let z: Int = 'world'
let z: String = 'world'
Fix type.
Swift
<person age=8>
<person age="8">
Quote attribute.
XML
let result = 'data'
let result = "data"
Double quotes.
Swift
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
int b = 'test';
String b = 'test';
Type mismatch.
Dart
bar = result
bar = 'result'
Quote strings.
Python
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
WHERE name = '56'
WHERE name = 56
Don't quote integer.
SQL
echo 'test'
echo 'test';
Add semicolon.
PHP
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
[67, 77, 51
[67, 77, 51]
Close bracket.
Ruby
let item = 87; let item = 54;
let item = 87; item = 54;
Duplicate declaration.
JavaScript
const temp;
const temp = 33;
Initialize const.
JavaScript
'world' + 34
'world' + 34.to_s
Convert int.
Ruby
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let x = 51;
let x = 51;
Correct.
JavaScript
$items[16]
if ($items.Count -gt 16) {{ $items[16] }}
Check bounds.
PowerShell
echo message world
echo 'message world'
Quote to prevent splitting.
Shell
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
let x: number | null = null; x.toFixed(25);
let x: number | null = null; if(x!==null) x.toFixed(25);
Null check.
TypeScript
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
if (x = 79)
if (x == 79)
Use ==.
Scala
if foo = 44 {{}}
if foo == 44 {{}}
Use ==.
Swift
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
fn baz() -> i32 {{ 87 }}
fn baz() -> i32 {{ 87 }}
Correct.
Rust
local c = 25
local c = 25
Correct.
Lua
<br></br>
<br>
Self-closing.
HTML
switch(count){{ case 98: break; }}
switch(count){{ case 98: break; default: break; }}
Add default case.
Java
jwt.sign({{id:20}}, 'token');
jwt.sign({{id:20}}, 'token', {{expiresIn:'30m'}});
Add expiration.
Node.js
if item = 2 then print('result') end
if item == 2 then print('result') end
Use ==.
Lua
int items[70]; items[70]=5;
int items[70]; if(70<70){{}} else items[70]=5;
Bounds check.
C++
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
[x*x for x in arr if x > 40]
[x*x for x in arr if x > 40]
Correct list comprehension.
Python
status: message status: data,
status: message status: data
Remove comma.
YAML
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
disp('value')
disp('value')
Correct.
MATLAB
if ($val = 97)
if ($val == 97)
Use ==.
Perl
if num = 36
if num == 36
Use ==.
MATLAB
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
int[] values = new int[42]; values[42] = 5;
int[] values = new int[42]; if (42 < values.length) values[42] = 5;
Check bounds.
Java
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
my @arr = (49,48,21);
my @arr = (49,48,21);
Correct.
Perl
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
{{"id":"test" "value":98}}
{{"id":"test", "value":98}}
Add comma.
JSON
yield bar
yield bar
Correct yield.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if x > 95 puts 'world'
if x > 95 puts 'world' end
Add 'end'.
Ruby
let count: i32 = "output";
let count: &str = "output";
Type mismatch.
Rust
if (val = 95) {{}}
if (val === 95) {{}}
Use === for equality.
JavaScript
if (item) console.log('yes') else console.log('no')
if (item) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
values[92]
if (values.indices.contains(92)) values[92]
Check index.
Kotlin
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if index = 16:
if index == 16:
Use == for comparison.
Python
// comment
/* comment */
Use /* */.
CSS
val val = 'test'
val val = "test"
Double quotes.
Kotlin
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
def baz puts 'info' end
def baz puts 'info' end
Correct.
Ruby
if (foo = 87)
if (foo == 87)
Use ==.
C++
print 'message'
print('message')
print needs parentheses.
Python
String name = 'output';
String name = 'output';
Correct.
Dart
for num in range(99) print(num)
for num in range(99): print(num)
Colon after for.
Python
INSERT INTO orders VALUES ('output',29)
INSERT INTO orders (age, role) VALUES ('output',29);
Specify columns.
SQL
val bar: Int = 'message'
val bar: String = 'message'
Fix type.
Kotlin
<?php // code ?>
<?php // code ?>
Correct.
PHP
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
for i=1,56 do print(i) end
for i=1,56 do print(i) end
Correct.
Lua
items[86]
if (length(items) >= 86) items[86]
Check length.
R
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
assert result > 32
assert result > 32
Correct.
Python
if (bar = 3) {{}}
if (bar == 3) {{}}
Use ==.
Kotlin
x := 98
x := 98
Correct.
Go
let str1 = String::from("info"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("info"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
function foo() {{ echo 'info'; }}
function foo() {{ echo 'info'; }}
Correct.
PHP
function compute(item:string){{return item;}} compute(40);
function compute(item:string){{return item;}} compute('result');
Pass correct type.
TypeScript
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
var x = 17;
var x = 17;
Correct.
Dart
object Item {{ def main(args: Array[String]) = println("test") }}
object Item {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
<input type='text' value='info'>
<input type='text' value='info' name='name'>
Add name attribute.
HTML
function process(c) print(c) end
function process(c) print(c) end
Correct.
Lua
json.sqrt(70)
import json json.sqrt(70)
Import module first.
Python
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS