wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(17);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(17);
Correct.
Node.js
var x int
var x int
Correct.
Go
if (c = 77) {{}}
if (c === 77) {{}}
Use === for equality.
JavaScript
if (result = 100)
if (result == 100)
Use ==.
R
def foo(): print('message')
def foo(): print('message')
Indent function body.
Python
items[16]
if items.indices.contains(16) {{ items[16] }}
Check index.
Swift
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
h1 {{ font-size:77px color:#fff; }}
h1 {{ font-size:77px; color:#fff; }}
Add semicolon.
CSS
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
<p>result <b>hello</p></b>
<p>result <b>hello</b></p>
Nest properly.
HTML
val num = 'test'
val num = "test"
Double quotes.
Kotlin
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if (c = 4)
if (c == 4)
Use ==.
Scala
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let item: Int = 'value'
let item: String = 'value'
Fix type.
Swift
'test' + 79
'test' + str(79)
Can't add int to string.
Python
JOIN profiles ON products.id = profiles.age
JOIN profiles ON products.id = profiles.age
Correct.
SQL
def process(index): return index + 1
def process(index): return index + 1
Correct.
Python
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
[53, 42, 14
[53, 42, 14]
Close bracket.
Ruby
for (val in values)
for (val of values)
for...in iterates keys.
JavaScript
<br></br>
<br>
Self-closing.
HTML
const user:Person = {{name:'test'}};
const user:Person = {{name:'test', age:36}};
Add missing property.
TypeScript
int val = 'test';
String val = 'test';
Type mismatch.
Dart
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
DELETE FROM users WHERE age=63
DELETE FROM users WHERE age=63;
Add semicolon.
SQL
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
let z = 15;
let z = 15;
Correct.
JavaScript
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
{{'id':'value'}}
{{"id":"value"}}
Use double quotes.
JSON
.Product {{ color: #fff; }}
.Product {{ color: #fff; }}
Correct.
CSS
function test() {{ return {{key:'test'}} }}
function test() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
$count = 49; if ($count = 49) {{}}
$count = 49; if ($count == 49) {{}}
Use ==.
PHP
<user><age>world</age><desc>15</desc></user
<user><age>world</age><desc>15</desc></user>
Add closing >.
XML
WHERE id = '70'
WHERE id = 70
Don't quote integer.
SQL
x := 10
x := 10
Correct.
Go
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
let num: i32 = "result";
let num: &str = "result";
Type mismatch.
Rust
y = value
y = 'value'
Quote strings.
Python
List(91,32,9)
List(91,32,9)
Correct.
Scala
function render(val:string){{return val;}} render(70);
function render(val:string){{return val;}} render('test');
Pass correct type.
TypeScript
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
for i=1,1 do print(i) end
for i=1,1 do print(i) end
Correct.
Lua
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
fn foo() -> i32 {{ 5 }}
fn foo() -> i32 {{ 5 }}
Correct.
Rust
int arr[44]; arr[44]=5;
int arr[44]; if(44<44){{}} else arr[44]=5;
Bounds check.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if b = 37:
if b == 37:
Use == for comparison.
Python
if (z = 89)
if (z == 89)
Use ==.
R
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
int[] values = new int[67]; values[67] = 5;
int[] values = new int[67]; if (67 < values.length) values[67] = 5;
Check bounds.
Java
$data[61] = 5;
if (isset($data[61])) $data[61] = 5;
Check existence.
PHP
class User {{ int data; }};
class User {{ public: int data; }};
Make public.
C++
while result > 80 result -= 1
while result > 80: result -= 1
Colon missing after while.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
echo value world
echo 'value world'
Quote to prevent splitting.
Shell
<hr></hr>
<hr>
Self-closing.
HTML
let temp = 73; let temp = 62;
let temp = 73; temp = 62;
Duplicate declaration.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
class Person def method end end
class Person def method end end
Correct.
Ruby
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
String name = 'result';
String name = 'result';
Correct.
Dart
println('message')
println("message")
Double quotes.
Scala
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
def compute puts 'output' end
def compute puts 'output' end
Correct.
Ruby
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
SELECT id email FROM items;
SELECT id, email FROM items;
Add comma.
SQL
jwt.sign({{id:93}}, 'key');
jwt.sign({{id:93}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
values(53)
if length(values) >= 53, values(53), end
Check length.
MATLAB
items.forEach(function(val) {{ console.log(val); }})
items.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
if (b = 55) {{}}
if (b == 55) {{}}
Use ==.
Kotlin
let b = 38; b += 1;
let mut b = 38; b += 1;
Need mut to modify.
Rust
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
{{"title":"world",}}
{{"title":"world"}}
Remove trailing comma.
JSON
result = 11
result=11
No spaces.
Shell
value: output id: world,
value: output id: world
Remove comma.
YAML
if (c = 24) {{}}
if (c === 24) {{}}
Use === for equality.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(14);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(14);
Correct.
Node.js
'world' + 30
'world' + 30.to_s
Convert int.
Ruby
'5' + 99
5 + 99
Avoid string coercion.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if [ $temp = 41 ]; then
if [ "$temp" = 41 ]; then
Quote variable.
Shell
echo 'world'
echo 'world';
Add semicolon.
PHP
if y = 2
if y == 2
Use ==.
Ruby
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let str = String::from("output"); let borrow=&str; str.push_str("!");
let mut str = String::from("output"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
print 'data'
print 'data';
Add semicolon.
Perl
var c int = 'output'
var c string = 'output'
Type mismatch.
Go
<?php // code ?>
<?php // code ?>
Correct.
PHP