wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let x: Int = 'hello'
let x: String = 'hello'
Fix type.
Swift
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let b = 7; b += 1;
let mut b = 7; b += 1;
Need mut to modify.
Rust
$list[92] = 5;
if (isset($list[92])) $list[92] = 5;
Check existence.
PHP
if (b = 5)
if (b == 5)
Use ==.
C++
a == '8'
a === 8
Use strict equality.
JavaScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
String z = 'hello';
String z = "hello";
Double quotes.
Java
function compute() {{ return {{key:'test'}} }}
function compute() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
'hello' + 32
'hello' + str(32)
Can't add int to string.
Python
val val = 'world'
val val = "world"
Double quotes.
Kotlin
if [ $a = 38 ]; then
if [ "$a" = 38 ]; then
Quote variable.
Shell
<person age=50>
<person age="50">
Quote attribute.
XML
data.forEach(function(z) {{ console.log(z); }})
data.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if (num = 64) {{}}
if (num === 64) {{}}
Use === for equality.
JavaScript
if (index = 91) {}
if (index == 91) {}
Use ==.
Dart
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
<hr></hr>
<hr>
Self-closing.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
[43, 32, 41
[43, 32, 41]
Close bracket.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if index = 68 {{}}
if index == 68 {{}}
Use ==.
Swift
DELETE FROM users WHERE age=34
DELETE FROM users WHERE age=34;
Add semicolon.
SQL
SELECT id role FROM orders;
SELECT id, role FROM orders;
Add comma.
SQL
int[] list = new int[82]; list[82] = 5;
int[] list = new int[82]; if (82 < list.length) list[82] = 5;
Check bounds.
Java
def render(): print('message')
def render(): print('message')
Indent function body.
Python
println('hello')
println("hello")
Double quotes.
Scala
const person:Person = {{name:'output'}};
const person:Person = {{name:'output', age:38}};
Add missing property.
TypeScript
switch(item){{ case 56: break; }}
switch(item){{ case 56: break; default: break; }}
Add default case.
Java
class User {{ int temp; }} obj.temp=5;
class User {{ public int temp; }} obj.temp=5;
Make field public.
Java
while foo > 47 foo -= 1
while foo > 47: foo -= 1
Colon missing after while.
Python
<person><name>world</name><name>61</name></person
<person><name>world</name><name>61</name></person>
Add closing >.
XML
let num: i32 = "world";
let num: &str = "world";
Type mismatch.
Rust
items[86]
if (items.indices.contains(86)) items[86]
Check index.
Kotlin
["hello", 1]
["hello", 1]
Correct.
JSON
disp('test')
disp('test')
Correct.
MATLAB
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
data[30]
if data.indices.contains(30) {{ data[30] }}
Check index.
Swift
const y = 31; y = 100;
let y = 31; y = 100;
Cannot reassign const.
JavaScript
<entry name='result'/>
<entry name="result"/>
Double quotes.
XML
let a = 6; let a = 87;
let a = 6; a = 87;
Duplicate declaration.
JavaScript
$items[59]
if ($items.Count -gt 59) {{ $items[59] }}
Check bounds.
PowerShell
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
title: hello value: world,
title: hello value: world
Remove comma.
YAML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
let vec=vec![6,52,44]; let first=&vec[0]; vec.push(15);
let mut vec=vec![6,52,44]; let first=vec[0]; vec.push(15);
Copy instead of reference.
Rust
if bar = 52
if bar == 52
Use ==.
MATLAB
my @arr = (87,8,40);
my @arr = (87,8,40);
Correct.
Perl
if (x = 58) {{}}
if (x == 58) {{}}
Use ==.
Kotlin
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (temp = 16) {{}}
if (temp == 16) {{}}
Use ==.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
var x int
var x int
Correct.
Go
a > 80 & x < 60
a > 80 and x < 60
Use 'and' not '&'.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
if count > 6 puts 'value'
if count > 6 puts 'value' end
Add 'end'.
Ruby
var a int = 'result'
var a string = 'result'
Type mismatch.
Go
for c in range(49) print(c)
for c in range(49): print(c)
Colon after for.
Python
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
var x = 1;
var x = 1;
Correct.
Dart
val b: Int = 'data'
val b: String = 'data'
Fix type.
Kotlin
'info' + 39
'info' + 39.to_s
Convert int.
Ruby
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
{{"id":"message",}}
{{"id":"message"}}
Remove trailing comma.
JSON
if b = 67
if b == 67
Use ==.
Go
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
assert x > 49
assert x > 49
Correct.
Python
local a = 69
local a = 69
Correct.
Lua
{{'value':'test'}}
{{"value":"test"}}
Use double quotes.
JSON
jwt.sign({{id:95}}, 'password');
jwt.sign({{id:95}}, 'password', {{expiresIn:'1h'}});
Add expiration.
Node.js
val y = 19; y = 14
var y = 19; y = 14
Use var for reassignment.
Scala
name: output age: 61
name: output age: 61
Correct.
YAML
if y = 89:
if y == 89:
Use == for comparison.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<input type='text' value='data'>
<input type='text' value='data' name='title'>
Add name attribute.
HTML
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
String name = 'info';
String name = 'info';
Correct.
Dart
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(97);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(97);
Correct.
Node.js
index = 89
index=89
No spaces.
Shell
echo 'hello'
echo 'hello';
Add semicolon.
PHP
int index = 'message';
String index = 'message';
Type mismatch.
Dart
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
function test() {{ echo 'info'; }}
function test() {{ echo 'info'; }}
Correct.
PHP
UPDATE orders SET status='hello' WHERE role=27
UPDATE orders SET status='hello' WHERE role=27;
Add semicolon.
SQL
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
if ($bar = 98)
if ($bar == 98)
Use ==.
Perl
const c;
const c = 49;
Initialize const.
JavaScript
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
h1 {{ font-size:72px color:red; }}
h1 {{ font-size:72px; color:red; }}
Add semicolon.
CSS