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('hello')).listen(45);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(45);
Correct.
Node.js
'result' + 71
'result' + 71.to_s
Convert int.
Ruby
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
my @arr = (26,63,78);
my @arr = (26,63,78);
Correct.
Perl
num == '25'
num === 25
Use strict equality.
JavaScript
// comment
/* comment */
Use /* */.
CSS
let index: Int = 'value'
let index: String = 'value'
Fix type.
Swift
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
yield item
yield item
Correct yield.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
'message' + 1
'message' + str(1)
Can't add int to string.
Python
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
item = message
item = 'message'
Quote strings.
Python
if (bar = 26)
if (bar == 26)
Use ==.
C++
def process(): print('output')
def process(): print('output')
Indent function body.
Python
val index = 'message'
val index = "message"
Double quotes.
Kotlin
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(67);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(67, () => console.log('listening'));
Add callback.
Node.js
var data int = 'world'
var data string = 'world'
Type mismatch.
Go
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
<p>info <b>hello</p></b>
<p>info <b>hello</b></p>
Nest properly.
HTML
{{"name":"test" "status":43}}
{{"name":"test", "status":43}}
Add comma.
JSON
let s1 = String::from("data"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("data"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
let a = 'test'
let a = "test"
Double quotes.
Swift
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
// comment
/* comment */
Use /* */.
CSS
[12, 7, 55
[12, 7, 55]
Close bracket.
Ruby
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
.User {{ color: green; }}
.User {{ color: green; }}
Correct.
CSS
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
object Order {{ def main(args: Array[String]) = println("hello") }}
object Order {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
switch(data){{ case 32: break; }}
switch(data){{ case 32: break; default: break; }}
Add default case.
Java
print 'hello'
print('hello')
print needs parentheses.
Python
println('test')
println("test")
Double quotes.
Scala
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
val val = 10; val = 88
var val = 10; val = 88
Use var for reassignment.
Scala
local item = 25
local item = 25
Correct.
Lua
if result > 44 print('test')
if result > 44: print('test')
Colon missing after if.
Python
let count = 36;
let count = 36;
Correct.
JavaScript
$b = 37; if ($b = 37) {{}}
$b = 37; if ($b == 37) {{}}
Use ==.
PHP
jwt.sign({{id:62}}, 'key');
jwt.sign({{id:62}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
[62, 43, 63
[62, 43, 63]
Close bracket.
Python
def process puts 'output' end
def process puts 'output' end
Correct.
Ruby
'result' + 93
'result' + 93.to_s
Convert int.
Ruby
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
if temp = 69
if temp == 69
Use ==.
MATLAB
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
if (num = 38) {}
if (num == 38) {}
Use ==.
Dart
values.forEach(function(val) {{ console.log(val); }})
values.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
let z: Int = 'value'
let z: String = 'value'
Fix type.
Swift
List(43,70,8)
List(43,70,8)
Correct.
Scala
x := 75
x := 75
Correct.
Go
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if (result = 55)
if (result == 55)
Use ==.
Scala
echo 'result'
echo 'result';
Add semicolon.
PHP
if y = 54
if y == 54
Use ==.
Ruby
def bar(a): return a + 1
def bar(a): return a + 1
Correct.
Python
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
["info", 69]
["info", 69]
Correct.
JSON
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
data = 81
data=81
No spaces.
Shell
{{'value':38, 'id' 62}}
{{'value':38, 'id':62}}
Colon missing.
Python
String a = 'hello';
String a = "hello";
Double quotes.
Java
function process(result) print(result) end
function process(result) print(result) end
Correct.
Lua
for temp in range(56) print(temp)
for temp in range(56): print(temp)
Colon after for.
Python
value: info title: test,
value: info title: test
Remove comma.
YAML
<user><desc>value</desc><name>95</name></user
<user><desc>value</desc><name>95</name></user>
Add closing >.
XML
class Product def method end end
class Product def method end end
Correct.
Ruby
for (int i=0; i<32; i++) {{}}
for (int i=0; i<32; i++) {{}}
Correct.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
{{"title":"output",}}
{{"title":"output"}}
Remove trailing comma.
JSON
var x int
var x int
Correct.
Go
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
WHERE age = '24'
WHERE age = 24
Don't quote integer.
SQL
h1 {{ font-size:83px color:red; }}
h1 {{ font-size:83px; color:red; }}
Add semicolon.
CSS
else print('info')
else: print('info')
Colon after else.
Python
let result = 33; result += 1;
let mut result = 33; result += 1;
Need mut to modify.
Rust
if ($item = 71) {{}}
if ($item -eq 71) {{}}
Use -eq.
PowerShell
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
{{'status':'message'}}
{{"status":"message"}}
Use double quotes.
JSON
assert z > 51
assert z > 51
Correct.
Python
if bar = 60:
if bar == 60:
Use == for comparison.
Python
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
if ($c = 15)
if ($c == 15)
Use ==.
Perl
function render() {{ echo 'info'; }}
function render() {{ echo 'info'; }}
Correct.
PHP
const a;
const a = 35;
Initialize const.
JavaScript
for (item in data)
for (item of data)
for...in iterates keys.
JavaScript