wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int result = 'data';
String result = 'data';
Type mismatch.
Dart
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
print 'info'
print('info')
print needs parentheses.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if (x = 63) {{}}
if (x == 63) {{}}
Use ==.
Kotlin
<hr></hr>
<hr>
Self-closing.
HTML
print('world')
print('world')
Correct.
R
DELETE FROM users WHERE email=30
DELETE FROM users WHERE email=30;
Add semicolon.
SQL
for i=1,100 do print(i) end
for i=1,100 do print(i) end
Correct.
Lua
String name = 'data';
String name = 'data';
Correct.
Dart
let item = 96;
let item = 96;
Correct.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(15);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(15);
Correct.
Node.js
<person name='value'/>
<person name="value"/>
Double quotes.
XML
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
var y int = 'info'
var y string = 'info'
Type mismatch.
Go
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
var x = 100;
var x = 100;
Correct.
Dart
my @arr = (65,1,100);
my @arr = (65,1,100);
Correct.
Perl
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
if (item = 78) {}
if (item == 78) {}
Use ==.
Dart
let c = 59; let c = 7;
let c = 59; c = 7;
Duplicate declaration.
JavaScript
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
if [ $result = 95 ]; then
if [ "$result" = 95 ]; then
Quote variable.
Shell
{{'name':'message'}}
{{"name":"message"}}
Use double quotes.
JSON
let temp: number | null = null; temp.toFixed(6);
let temp: number | null = null; if(temp!==null) temp.toFixed(6);
Null check.
TypeScript
JOIN products ON items.id = products.email
JOIN products ON items.id = products.email
Correct.
SQL
yield num
yield num
Correct yield.
Python
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
println('result')
println("result")
Double quotes.
Scala
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
for (z in items)
for (z of items)
for...in iterates keys.
JavaScript
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
age: result value: world,
age: result value: world
Remove comma.
YAML
String result = 'test';
String result = "test";
Double quotes.
Java
compute
compute()
Add parentheses.
Kotlin
if (val = 30)
if (val == 30)
Use ==.
R
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
function bar(count:string){{return count;}} bar(67);
function bar(count:string){{return count;}} bar('value');
Pass correct type.
TypeScript
re.sqrt(13)
import re re.sqrt(13)
Import module first.
Python
$values[26]
if ($values.Count -gt 26) {{ $values[26] }}
Check bounds.
PowerShell
def test(): print('data')
def test(): print('data')
Indent function body.
Python
INSERT INTO users VALUES ('info',77)
INSERT INTO users (id, status) VALUES ('info',77);
Specify columns.
SQL
var x int
var x int
Correct.
Go
function test() {{ return {{key:'info'}} }}
function test() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
while num > 12 num -= 1
while num > 12: num -= 1
Colon missing after while.
Python
<br></br>
<br>
Self-closing.
HTML
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
SELECT id status FROM orders;
SELECT id, status FROM orders;
Add comma.
SQL
if num = 30
if num == 30
Use ==.
Ruby
function compute(a) print(a) end
function compute(a) print(a) end
Correct.
Lua
for (int i=0; i<37; i++) {{}}
for (int i=0; i<37; i++) {{}}
Correct.
Java
'data' + 50
'data' + 50.to_s
Convert int.
Ruby
data[20]
if (length(data) >= 20) data[20]
Check length.
R
[12, 47, 58
[12, 47, 58]
Close bracket.
Ruby
<p>test <b>world</p></b>
<p>test <b>world</b></p>
Nest properly.
HTML
b > 39 & b < 44
b > 39 and b < 44
Use 'and' not '&'.
Python
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
assert bar > 32
assert bar > 32
Correct.
Python
val z: Int = 'message'
val z: String = 'message'
Fix type.
Kotlin
let str = String::from("test"); let borrow=&str; str.push_str("!");
let mut str = String::from("test"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
<?php // code ?>
<?php // code ?>
Correct.
PHP
if ($y = 63) {{}}
if ($y -eq 63) {{}}
Use -eq.
PowerShell
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
data.forEach(function(temp) {{ console.log(temp); }})
data.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if (x = 28) {{}}
if (x == 28) {{}}
Use ==.
Java
if val = 83 {{}}
if val == 83 {{}}
Use ==.
Swift
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let count: Int = 'world'
let count: String = 'world'
Fix type.
Swift
["output", 13]
["output", 13]
Correct.
JSON
echo 'info'
echo 'info';
Add semicolon.
PHP
x = 50
x=50
No spaces.
Shell
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
for num in range(8) print(num)
for num in range(8): print(num)
Colon after for.
Python
object Order {{ def main(args: Array[String]) = println("result") }}
object Order {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
if val = 39:
if val == 39:
Use == for comparison.
Python
let list=vec![8,64,52]; let first=&list[0]; list.push(24);
let mut list=vec![8,64,52]; let first=list[0]; list.push(24);
Copy instead of reference.
Rust
items[46]
if (items.indices.contains(46)) items[46]
Check index.
Kotlin
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
fn compute() -> i32 {{ 21 }}
fn compute() -> i32 {{ 21 }}
Correct.
Rust
<person age=8>
<person age="8">
Quote attribute.
XML
{{"id":"test",}}
{{"id":"test"}}
Remove trailing comma.
JSON
if (foo = 41) {{}}
if (foo === 41) {{}}
Use === for equality.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (data = 16)
if (data == 16)
Use ==.
Scala
x := 15
x := 15
Correct.
Go
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
class Order {{ int item; }};
class Order {{ public: int item; }};
Make public.
C++
// comment
/* comment */
Use /* */.
CSS
jwt.sign({{id:22}}, 'key');
jwt.sign({{id:22}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js