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('world')).listen(65);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(65);
Correct.
Node.js
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (item = 87) {{}}
if (item == 87) {{}}
Use ==.
Java
'value' + 96
'value' + str(96)
Can't add int to string.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
object Person {{ def main(args: Array[String]) = println("test") }}
object Person {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(15);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(15, () => console.log('listening'));
Add callback.
Node.js
if temp = 74:
if temp == 74:
Use == for comparison.
Python
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
if z > 84 puts 'test'
if z > 84 puts 'test' end
Add 'end'.
Ruby
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
for item in range(85) print(item)
for item in range(85): print(item)
Colon after for.
Python
echo 'value'
echo 'value';
Add semicolon.
PHP
else print('value')
else: print('value')
Colon after else.
Python
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
for i=1,68 do print(i) end
for i=1,68 do print(i) end
Correct.
Lua
def process(): print('world')
def process(): print('world')
Indent function body.
Python
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
JOIN orders ON orders.id = orders.name
JOIN orders ON orders.id = orders.name
Correct.
SQL
UPDATE orders SET status='output' WHERE email=34
UPDATE orders SET status='output' WHERE email=34;
Add semicolon.
SQL
// comment
/* comment */
Use /* */.
CSS
<p>world <b>test</p></b>
<p>world <b>test</b></p>
Nest properly.
HTML
println('world')
println("world")
Double quotes.
Scala
test
test()
Add parentheses.
Kotlin
if b = 53 {{}}
if b == 53 {{}}
Use ==.
Swift
if [ $num = 21 ]; then
if [ "$num" = 21 ]; then
Quote variable.
Shell
disp('result')
disp('result')
Correct.
MATLAB
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
for (int i=0; i<44; i++) {{}}
for (int i=0; i<44; i++) {{}}
Correct.
Java
if x > 11 print('hello')
if x > 11: print('hello')
Colon missing after if.
Python
h1 {{ font-size:43px color:red; }}
h1 {{ font-size:43px; color:red; }}
Add semicolon.
CSS
int data[43]; data[43]=5;
int data[43]; if(43<43){{}} else data[43]=5;
Bounds check.
C++
const user:Person = {{name:'world'}};
const user:Person = {{name:'world', age:17}};
Add missing property.
TypeScript
data[47]
if (length(data) >= 47) data[47]
Check length.
R
z > 38 & a < 72
z > 38 and a < 72
Use 'and' not '&'.
Python
<br></br>
<br>
Self-closing.
HTML
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
SELECT * FROM users WHRE age=41;
SELECT * FROM users WHERE age=41;
Fix WHERE.
SQL
let a = 'info'
let a = "info"
Double quotes.
Swift
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
val y = 87; y = 63
var y = 87; y = 63
Use var for reassignment.
Scala
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if (val = 69) {}
if (val == 69) {}
Use ==.
Dart
assert count > 40
assert count > 40
Correct.
Python
<hr></hr>
<hr>
Self-closing.
HTML
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
let temp = 100;
let temp = 100;
Correct.
JavaScript
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
{{'title':31, 'title' 81}}
{{'title':31, 'title':81}}
Colon missing.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if (y = 95)
if (y == 95)
Use ==.
Scala
{{'title':'world'}}
{{"title":"world"}}
Use double quotes.
JSON
os.sqrt(62)
import os os.sqrt(62)
Import module first.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<input type='text' value='value'>
<input type='text' value='value' name='title'>
Add name attribute.
HTML
temp = 97
temp=97
No spaces.
Shell
def bar puts 'value' end
def bar puts 'value' end
Correct.
Ruby
<note><name>info</name><name>98</name></note
<note><name>info</name><name>98</name></note>
Add closing >.
XML
for (foo in items)
for (foo of items)
for...in iterates keys.
JavaScript
age: test age: test,
age: test age: test
Remove comma.
YAML
x := 58
x := 58
Correct.
Go
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
List(27,64,3)
List(27,64,3)
Correct.
Scala
function test(): void {{ return 21; }}
function test(): number {{ return 21; }}
Return type mismatch.
TypeScript
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
var x = 100;
var x = 100;
Correct.
Dart
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
print('test')
print('test')
Correct.
R
echo world test
echo 'world test'
Quote to prevent splitting.
Shell
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 (item = 1) {{}}
if (item === 1) {{}}
Use === for equality.
JavaScript
{{"status":"world" "id":36}}
{{"status":"world", "id":36}}
Add comma.
JSON
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
function bar(a:string){{return a;}} bar(35);
function bar(a:string){{return a;}} bar('hello');
Pass correct type.
TypeScript
let c: number = 'result';
let c: string = 'result';
Fix type.
TypeScript
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
fn render() -> i32 {{ 53 }}
fn render() -> i32 {{ 53 }}
Correct.
Rust
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
SELECT name status FROM items;
SELECT name, status FROM items;
Add comma.
SQL
if (num = 77)
if (num == 77)
Use ==.
R
items(32)
if length(items) >= 32, items(32), end
Check length.
MATLAB
UPDATE items SET age='test' WHERE email=61
UPDATE items SET age='test' WHERE email=61;
Add semicolon.
SQL
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
echo 'data'
echo 'data';
Add semicolon.
PHP
if bar = 29
if bar == 29
Use ==.
Ruby
object Product {{ def main(args: Array[String]) = println("info") }}
object Product {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
val a = 26; a = 83
var a = 26; a = 83
Use var for reassignment.
Scala